42 #include "llvm/ADT/ScopeExit.h"
43 #include "llvm/ADT/SmallString.h"
44 #include "llvm/ADT/STLExtras.h"
45 #include "llvm/ADT/StringExtras.h"
49 using namespace clang;
61 class CheckDefaultArgumentVisitor
64 const Expr *DefaultArg;
67 CheckDefaultArgumentVisitor(
Sema &S,
const Expr *DefaultArg)
68 : S(S), DefaultArg(DefaultArg) {}
73 bool VisitLambdaExpr(
const LambdaExpr *Lambda);
78 bool CheckDefaultArgumentVisitor::VisitExpr(
const Expr *
Node) {
79 bool IsInvalid =
false;
80 for (
const Stmt *SubStmt :
Node->children())
81 IsInvalid |= Visit(SubStmt);
88 bool CheckDefaultArgumentVisitor::VisitDeclRefExpr(
const DeclRefExpr *DRE) {
90 if (
const auto *Param = dyn_cast<ParmVarDecl>(
Decl)) {
101 diag::err_param_default_argument_references_param)
102 << Param->getDeclName() << DefaultArg->getSourceRange();
103 }
else if (
const auto *VDecl = dyn_cast<VarDecl>(
Decl)) {
115 if (VDecl->isLocalVarDecl() && !DRE->
isNonOdrUse())
117 diag::err_param_default_argument_references_local)
118 << VDecl->getDeclName() << DefaultArg->getSourceRange();
125 bool CheckDefaultArgumentVisitor::VisitCXXThisExpr(
const CXXThisExpr *ThisE) {
130 diag::err_param_default_argument_references_this)
134 bool CheckDefaultArgumentVisitor::VisitPseudoObjectExpr(
139 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(E)) {
140 E = OVE->getSourceExpr();
141 assert(E &&
"pseudo-object binding without source expression?");
149 bool CheckDefaultArgumentVisitor::VisitLambdaExpr(
const LambdaExpr *Lambda) {
156 return S.
Diag(Lambda->
getBeginLoc(), diag::err_lambda_capture_default_arg);
186 llvm_unreachable(
"should not see unresolved exception specs here");
215 "should not generate implicit declarations for dependent cases");
219 assert(EST ==
EST_Dynamic &&
"EST case not considered earlier.");
221 "Shouldn't collect exceptions when throw-all is guaranteed.");
226 Exceptions.push_back(E);
254 if (Self->canThrow(S))
261 diag::err_typecheck_decl_incomplete_type))
276 if (Result.isInvalid())
278 Arg = Result.getAs<
Expr>();
280 CheckCompletedExpr(Arg, EqualLoc);
293 UnparsedDefaultArgInstantiationsMap::iterator InstPos
296 for (
unsigned I = 0, N = InstPos->second.size(); I != N; ++I)
297 InstPos->second[I]->setUninstantiatedDefaultArg(Arg);
310 if (!param || !DefaultArg)
324 Diag(EqualLoc, diag::err_param_default_argument)
338 Diag(EqualLoc, diag::err_param_default_argument_on_parameter_pack)
346 if (Result.isInvalid())
349 DefaultArg = Result.getAs<
Expr>();
352 CheckDefaultArgumentVisitor DefaultArgChecker(*
this, DefaultArg);
353 if (DefaultArgChecker.Visit(DefaultArg))
405 if (MightBeFunction) {
409 MightBeFunction =
false;
412 for (
unsigned argIdx = 0, e = chunk.
Fun.
NumParams; argIdx != e;
416 std::unique_ptr<CachedTokens> Toks =
419 if (Toks->size() > 1)
421 Toks->back().getLocation());
433 MightBeFunction =
false;
440 return P->hasDefaultArg() && !P->hasInheritedDefaultArg();
450 bool Invalid =
false;
461 for (; PrevForDefaultArgs;
509 for (
unsigned p = 0, NumParams = PrevForDefaultArgs
512 p < NumParams; ++p) {
516 bool OldParamHasDfl = OldParam ? OldParam->
hasDefaultArg() :
false;
519 if (OldParamHasDfl && NewParamHasDfl) {
520 unsigned DiagDefaultParamID =
521 diag::err_param_default_argument_redefinition;
536 DiagDefaultParamID = diag::ext_param_default_argument_redefinition;
554 for (
auto Older = PrevForDefaultArgs;
556 Older = Older->getPreviousDecl();
557 OldParam = Older->getParamDecl(p);
562 }
else if (OldParamHasDfl) {
580 }
else if (NewParamHasDfl) {
584 diag::err_param_default_argument_template_redecl)
587 diag::note_template_prev_declaration)
618 if (Record->getDescribedClassTemplate())
620 else if (isa<ClassTemplatePartialSpecializationDecl>(Record))
627 diag::err_param_default_argument_member_template_redecl)
637 if (isa<CXXConstructorDecl>(New) &&
641 if (NewSM != OldSM) {
644 Diag(NewParam->
getLocation(), diag::err_default_arg_makes_ctor_special)
679 if (isa<CXXDeductionGuideDecl>(New) &&
691 Diag(New->
getLocation(), diag::err_friend_decl_with_def_arg_redeclared);
725 if (!TemplateParamLists.empty()) {
728 Diag(TemplateParamLists.front()->getTemplateLoc(),
729 diag::err_decomp_decl_template);
735 ? diag::ext_decomp_decl
737 ? diag::ext_decomp_decl_cond
738 : diag::warn_cxx14_compat_decomp_decl)
756 if (
auto SCS = DS.getStorageClassSpec()) {
759 CPlusPlus20SpecifierLocs.push_back(DS.getStorageClassSpecLoc());
762 BadSpecifierLocs.push_back(DS.getStorageClassSpecLoc());
765 if (
auto TSCS = DS.getThreadStorageClassSpec()) {
767 CPlusPlus20SpecifierLocs.push_back(DS.getThreadStorageClassSpecLoc());
769 if (DS.hasConstexprSpecifier()) {
770 BadSpecifiers.push_back(
772 BadSpecifierLocs.push_back(DS.getConstexprSpecLoc());
774 if (DS.isInlineSpecified()) {
775 BadSpecifiers.push_back(
"inline");
776 BadSpecifierLocs.push_back(DS.getInlineSpecLoc());
778 if (!BadSpecifiers.empty()) {
779 auto &&Err =
Diag(BadSpecifierLocs.front(), diag::err_decomp_decl_spec);
780 Err << (
int)BadSpecifiers.size()
781 << llvm::join(BadSpecifiers.begin(), BadSpecifiers.end(),
" ");
784 for (
auto Loc : BadSpecifierLocs)
786 }
else if (!CPlusPlus20Specifiers.empty()) {
787 auto &&Warn =
Diag(CPlusPlus20SpecifierLocs.front(),
789 ? diag::warn_cxx17_compat_decomp_decl_spec
790 : diag::ext_decomp_decl_spec);
791 Warn << (
int)CPlusPlus20Specifiers.size()
792 << llvm::join(CPlusPlus20Specifiers.begin(),
793 CPlusPlus20Specifiers.end(),
" ");
794 for (
auto Loc : CPlusPlus20SpecifierLocs)
806 Diag(DS.getVolatileSpecLoc(),
807 diag::warn_deprecated_volatile_structured_binding);
827 ? diag::err_decomp_decl_parens
828 : diag::err_decomp_decl_type)
852 Previous.getFoundDecl()->isTemplateParameter()) {
871 auto *Old =
Previous.getRepresentativeDecl();
872 Diag(B.NameLoc, diag::err_redefinition) << B.Name;
873 Diag(Old->getLocation(), diag::note_previous_definition);
890 bool AddToScope =
true;
909 if ((int64_t)
Bindings.size() != NumElems) {
910 S.
Diag(Src->
getLocation(), diag::err_decomp_decl_wrong_number_bindings)
923 E = GetInit(Loc, E.
get(), I++);
926 B->setBinding(ElemType, E.
get());
938 S,
Bindings, Src, DecompType, NumElems, ElemType,
969 S,
Bindings, Src, DecompType, llvm::APSInt::get(2),
973 return S.CreateBuiltinUnaryOp(Loc, I ? UO_Imag : UO_Real, Base);
981 llvm::raw_svector_ostream OS(SS);
1000 auto DiagnoseMissing = [&] {
1010 return DiagnoseMissing();
1020 return DiagnoseMissing();
1021 if (Result.isAmbiguous())
1026 Result.suppressDiagnostics();
1028 S.
Diag(Loc, diag::err_std_type_trait_not_class_template) << Trait;
1040 Loc, TraitTy, DiagID,
1047 assert(RD &&
"specialization of class template is not a class?");
1066 namespace {
enum class IsTupleLike { TupleLike, NotTupleLike,
Error }; }
1084 return IsTupleLike::NotTupleLike;
1093 : R(R), Args(Args) {}
1096 return S.
Diag(Loc, diag::err_decomp_decl_std_tuple_size_not_constant)
1100 } Diagnoser(R, Args);
1111 return IsTupleLike::TupleLike;
1126 S, R, Loc,
"tuple_element", Args,
1127 diag::err_decomp_decl_std_tuple_element_not_specialized))
1133 S.
Diag(Loc, diag::err_decomp_decl_std_tuple_element_not_specialized)
1145 struct InitializingBinding {
1154 ~InitializingBinding() {
1164 if ((int64_t)
Bindings.size() != TupleSize) {
1165 S.
Diag(Src->
getLocation(), diag::err_decomp_decl_wrong_number_bindings)
1181 bool UseMemberGet =
false;
1191 dyn_cast<FunctionTemplateDecl>(D->getUnderlyingDecl())) {
1193 if (TPL->
size() != 0 &&
1194 isa<NonTypeTemplateParmDecl>(TPL->
getParam(0))) {
1196 UseMemberGet =
true;
1205 InitializingBinding InitContext(S, B);
1228 MemberGet, &Args,
nullptr);
1262 B->getDeclName().getAsIdentifierInfo(), RefType,
1266 RefVD->setImplicit();
1268 RefVD->setInlineSpecified();
1269 RefVD->getLexicalDeclContext()->addHiddenDecl(RefVD);
1280 RefVD->setInit(E.
get());
1289 B->setBinding(T, E.
get());
1304 return Specifier->getType()->getAsCXXRecordDecl()->hasDirectFields();
1313 ClassWithFields = RD;
1325 for (
auto &
P : Paths) {
1329 BestPath->back().Base->getType())) {
1331 S.
Diag(Loc, diag::err_decomp_decl_multiple_bases_with_members)
1332 <<
false << RD << BestPath->back().Base->getType()
1333 <<
P.back().Base->getType();
1335 }
else if (
P.Access < BestPath->
Access) {
1341 QualType BaseType = BestPath->back().Base->getType();
1343 S.
Diag(Loc, diag::err_decomp_decl_ambiguous_base)
1350 *BestPath, diag::err_decomp_decl_inaccessible_base);
1361 S.
Diag(Loc, diag::err_decomp_decl_multiple_bases_with_members)
1362 << (ClassWithFields == RD) << RD << ClassWithFields
1363 << Paths.front().back().Base->getType();
1374 diag::err_incomplete_type))
1386 auto DiagnoseBadNumberOfBindings = [&]() ->
bool {
1387 unsigned NumFields = llvm::count_if(
1388 RD->
fields(), [](
FieldDecl *FD) { return !FD->isUnnamedBitfield(); });
1389 assert(
Bindings.size() != NumFields);
1390 S.
Diag(Src->
getLocation(), diag::err_decomp_decl_wrong_number_bindings)
1400 for (
auto *FD : RD->
fields()) {
1401 if (FD->isUnnamedBitfield())
1406 if (!FD->getDeclName()) {
1413 if (FD->isAnonymousStructOrUnion()) {
1416 S.
Diag(FD->getLocation(), diag::note_declared_at);
1425 return DiagnoseBadNumberOfBindings();
1436 BasePair.
getAccess(), FD->getAccess())));
1459 if (FD->isMutable())
1465 return DiagnoseBadNumberOfBindings();
1513 case IsTupleLike::TupleLike:
1518 case IsTupleLike::NotTupleLike:
1527 << DD << !RD << DecompType;
1550 "Should only be called if types are otherwise the same.");
1561 NewType =
P->getPointeeType();
1594 if (FTD->isMemberSpecialization())
1618 diag::err_param_default_argument_missing_name)
1622 diag::err_param_default_argument_missing);
1630 template <
typename... Ts>
1640 std::forward<Ts>(DiagArgs)...);
1646 llvm_unreachable(
"unknown CheckConstexprKind");
1655 T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
1663 SemaRef.
Diag(Loc, diag::note_constexpr_dtor_subobject)
1671 if (!Check(B.getBaseTypeLoc(), B.getType(),
nullptr))
1674 if (!Check(FD->getLocation(), FD->getType(), FD))
1684 unsigned ArgIndex = 0;
1687 e = FT->param_type_end();
1688 i != e; ++i, ++ArgIndex) {
1692 diag::err_constexpr_non_literal_param, ArgIndex + 1,
1705 diag::err_constexpr_non_literal_return,
1721 default: llvm_unreachable(
"Invalid tag kind for record diagnostic!");
1752 << isa<CXXConstructorDecl>(NewFD)
1754 for (
const auto &I : RD->
vbases())
1755 Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here)
1756 << I.getSourceRange();
1761 if (!isa<CXXConstructorDecl>(NewFD)) {
1766 const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD);
1770 Diag(Method->
getLocation(), diag::warn_cxx17_compat_constexpr_virtual);
1783 if (WrittenVirtual != Method)
1785 diag::note_overridden_virtual_function);
1795 if (
auto *Dtor = dyn_cast<CXXDestructorDecl>(NewFD)) {
1799 if (!Dtor->getParent()->defaultedDestructorIsConstexpr()) {
1813 "CheckConstexprFunctionDefinition called on function with no body");
1828 for (
const auto *DclIt : DS->
decls()) {
1829 switch (DclIt->getKind()) {
1830 case Decl::StaticAssert:
1832 case Decl::UsingShadow:
1833 case Decl::UsingDirective:
1834 case Decl::UnresolvedUsingTypename:
1835 case Decl::UnresolvedUsingValue:
1836 case Decl::UsingEnum:
1844 case Decl::TypeAlias: {
1847 const auto *TN = cast<TypedefNameDecl>(DclIt);
1848 if (TN->getUnderlyingType()->isVariablyModifiedType()) {
1851 TypeLoc TL = TN->getTypeSourceInfo()->getTypeLoc();
1854 << isa<CXXConstructorDecl>(Dcl);
1862 case Decl::CXXRecord:
1864 if (cast<TagDecl>(DclIt)->isThisDeclarationADefinition()) {
1868 ? diag::warn_cxx11_compat_constexpr_type_definition
1869 : diag::ext_constexpr_type_definition)
1870 << isa<CXXConstructorDecl>(Dcl);
1877 case Decl::EnumConstant:
1878 case Decl::IndirectField:
1885 case Decl::Decomposition: {
1890 const auto *VD = cast<VarDecl>(DclIt);
1891 if (VD->isThisDeclarationADefinition()) {
1892 if (VD->isStaticLocal()) {
1894 SemaRef.
Diag(VD->getLocation(),
1896 ? diag::warn_cxx20_compat_constexpr_static_var
1897 : diag::ext_constexpr_static_var)
1898 << isa<CXXConstructorDecl>(Dcl)
1904 if (!SemaRef.
LangOpts.CPlusPlus2b &&
1906 diag::err_constexpr_local_var_non_literal_type,
1907 isa<CXXConstructorDecl>(Dcl)))
1909 if (!VD->getType()->isDependentType() &&
1910 !VD->hasInit() && !VD->isCXXForRangeDecl()) {
1915 ? diag::warn_cxx17_compat_constexpr_local_var_no_init
1916 : diag::ext_constexpr_local_var_no_init)
1917 << isa<CXXConstructorDecl>(Dcl);
1925 SemaRef.
Diag(VD->getLocation(),
1927 ? diag::warn_cxx11_compat_constexpr_local_var
1928 : diag::ext_constexpr_local_var)
1929 << isa<CXXConstructorDecl>(Dcl);
1936 case Decl::NamespaceAlias:
1937 case Decl::Function:
1946 SemaRef.
Diag(DS->
getBeginLoc(), diag::err_constexpr_body_invalid_stmt)
1947 << isa<CXXConstructorDecl>(Dcl) << Dcl->
isConsteval();
1972 llvm::SmallSet<Decl*, 16> &Inits,
1980 if (Field->isInvalidDecl())
1983 if (Field->isUnnamedBitfield())
1989 if (Field->isAnonymousStructOrUnion() &&
1990 (Field->getType()->isUnionType()
1991 ? !Field->getType()->getAsCXXRecordDecl()->hasVariantMembers()
1992 : Field->getType()->getAsCXXRecordDecl()->isEmpty()))
1995 if (!Inits.count(Field)) {
2000 ? diag::warn_cxx17_compat_constexpr_ctor_missing_init
2001 : diag::ext_constexpr_ctor_missing_init);
2004 SemaRef.
Diag(Field->getLocation(),
2005 diag::note_constexpr_ctor_missing_init);
2009 }
else if (Field->isAnonymousStructOrUnion()) {
2011 for (
auto *I : RD->
fields())
2014 if (!RD->
isUnion() || Inits.count(I))
2031 switch (S->getStmtClass()) {
2032 case Stmt::NullStmtClass:
2036 case Stmt::DeclStmtClass:
2046 case Stmt::ReturnStmtClass:
2048 if (isa<CXXConstructorDecl>(Dcl)) {
2051 Cxx1yLoc = S->getBeginLoc();
2055 ReturnStmts.push_back(S->getBeginLoc());
2058 case Stmt::AttributedStmtClass:
2062 SemaRef, Dcl, cast<AttributedStmt>(S)->getSubStmt(), ReturnStmts,
2063 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind);
2065 case Stmt::CompoundStmtClass: {
2068 Cxx1yLoc = S->getBeginLoc();
2071 for (
auto *BodyIt : CompStmt->
body()) {
2073 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2079 case Stmt::IfStmtClass: {
2082 Cxx1yLoc = S->getBeginLoc();
2084 IfStmt *If = cast<IfStmt>(S);
2086 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2090 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2095 case Stmt::WhileStmtClass:
2096 case Stmt::DoStmtClass:
2097 case Stmt::ForStmtClass:
2098 case Stmt::CXXForRangeStmtClass:
2099 case Stmt::ContinueStmtClass:
2105 Cxx1yLoc = S->getBeginLoc();
2106 for (
Stmt *SubStmt : S->children()) {
2109 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2114 case Stmt::SwitchStmtClass:
2115 case Stmt::CaseStmtClass:
2116 case Stmt::DefaultStmtClass:
2117 case Stmt::BreakStmtClass:
2121 Cxx1yLoc = S->getBeginLoc();
2122 for (
Stmt *SubStmt : S->children()) {
2125 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2130 case Stmt::LabelStmtClass:
2131 case Stmt::GotoStmtClass:
2133 Cxx2bLoc = S->getBeginLoc();
2134 for (
Stmt *SubStmt : S->children()) {
2137 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2142 case Stmt::GCCAsmStmtClass:
2143 case Stmt::MSAsmStmtClass:
2145 case Stmt::CXXTryStmtClass:
2147 Cxx2aLoc = S->getBeginLoc();
2148 for (
Stmt *SubStmt : S->children()) {
2151 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2156 case Stmt::CXXCatchStmtClass:
2160 SemaRef, Dcl, cast<CXXCatchStmt>(S)->getHandlerBlock(), ReturnStmts,
2161 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2171 Cxx1yLoc = S->getBeginLoc();
2176 SemaRef.
Diag(S->getBeginLoc(), diag::err_constexpr_body_invalid_stmt)
2177 << isa<CXXConstructorDecl>(Dcl) << Dcl->
isConsteval();
2192 if (isa<CXXTryStmt>(Body)) {
2214 ? diag::ext_constexpr_function_try_block_cxx20
2215 : diag::warn_cxx17_compat_constexpr_function_try_block)
2216 << isa<CXXConstructorDecl>(Dcl);
2230 Cxx1yLoc, Cxx2aLoc, Cxx2bLoc,
Kind))
2241 }
else if (Cxx2bLoc.
isValid()) {
2242 SemaRef.
Diag(Cxx2bLoc,
2244 ? diag::warn_cxx20_compat_constexpr_body_invalid_stmt
2245 : diag::ext_constexpr_body_invalid_stmt_cxx2b)
2246 << isa<CXXConstructorDecl>(Dcl);
2247 }
else if (Cxx2aLoc.
isValid()) {
2248 SemaRef.
Diag(Cxx2aLoc,
2250 ? diag::warn_cxx17_compat_constexpr_body_invalid_stmt
2251 : diag::ext_constexpr_body_invalid_stmt_cxx20)
2252 << isa<CXXConstructorDecl>(Dcl);
2253 }
else if (Cxx1yLoc.
isValid()) {
2254 SemaRef.
Diag(Cxx1yLoc,
2256 ? diag::warn_cxx11_compat_constexpr_body_invalid_stmt
2257 : diag::ext_constexpr_body_invalid_stmt)
2258 << isa<CXXConstructorDecl>(Dcl);
2262 = dyn_cast<CXXConstructorDecl>(Dcl)) {
2271 if (Constructor->getNumCtorInitializers() == 0 &&
2277 ? diag::warn_cxx17_compat_constexpr_union_ctor_no_init
2278 : diag::ext_constexpr_union_ctor_no_init);
2283 }
else if (!Constructor->isDependentContext() &&
2284 !Constructor->isDelegatingConstructor()) {
2285 assert(RD->
getNumVBases() == 0 &&
"constexpr ctor with virtual bases");
2289 bool AnyAnonStructUnionMembers =
false;
2290 unsigned Fields = 0;
2292 E = RD->
field_end(); I != E; ++I, ++Fields) {
2293 if (I->isAnonymousStructOrUnion()) {
2294 AnyAnonStructUnionMembers =
true;
2302 if (AnyAnonStructUnionMembers ||
2303 Constructor->getNumCtorInitializers() != RD->
getNumBases() + Fields) {
2307 llvm::SmallSet<Decl*, 16> Inits;
2308 for (
const auto *I: Constructor->inits()) {
2312 Inits.insert(
ID->chain_begin(),
ID->chain_end());
2315 bool Diagnosed =
false;
2316 for (
auto *I : RD->
fields())
2323 if (ReturnStmts.empty()) {
2334 OK ? diag::warn_cxx11_compat_constexpr_body_no_return
2335 : diag::err_constexpr_body_no_return)
2349 }
else if (ReturnStmts.size() > 1) {
2355 ? diag::warn_cxx11_compat_constexpr_body_multiple_return
2356 : diag::ext_constexpr_body_multiple_return);
2357 for (
unsigned I = 0; I < ReturnStmts.size() - 1; ++I)
2358 SemaRef.
Diag(ReturnStmts[I],
2359 diag::note_constexpr_body_previous_return);
2387 diag::ext_constexpr_function_never_constant_expr)
2388 << isa<CXXConstructorDecl>(Dcl) << Dcl->
isConsteval();
2389 for (
size_t I = 0, N =
Diags.size(); I != N; ++I)
2414 return dyn_cast_or_null<CXXRecordDecl>(DC);
2417 return dyn_cast_or_null<CXXRecordDecl>(
CurContext);
2442 CurDecl = dyn_cast_or_null<CXXRecordDecl>(DC);
2444 CurDecl = dyn_cast_or_null<CXXRecordDecl>(
CurContext);
2462 Class = Class->getCanonicalDecl();
2464 for (
const auto &I : Current->bases()) {
2473 if (
Base->getCanonicalDecl() == Class)
2476 Queue.push_back(
Base);
2482 Current = Queue.pop_back_val();
2505 if (Class->isUnion()) {
2506 Diag(Class->getLocation(), diag::err_base_clause_on_union)
2513 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
2525 if (BaseDecl->getCanonicalDecl() == Class->getCanonicalDecl() ||
2526 ((BaseDecl = BaseDecl->getDefinition()) &&
2528 Diag(BaseLoc, diag::err_circular_inheritance)
2531 if (BaseDecl->getCanonicalDecl() != Class->getCanonicalDecl())
2532 Diag(BaseDecl->getLocation(), diag::note_previous_decl)
2545 if (!Class->getTypeForDecl()->isDependentType())
2546 Class->setInvalidDecl();
2549 Access, TInfo, EllipsisLoc);
2554 Diag(BaseLoc, diag::err_base_must_be_class) << SpecifierRange;
2561 Diag(BaseLoc, diag::err_union_as_base_class) << SpecifierRange;
2568 if (
auto *BaseTemplate = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
2580 diag::err_incomplete_base_class, SpecifierRange)) {
2581 Class->setInvalidDecl();
2587 assert(BaseDecl &&
"Record type has no declaration");
2589 assert(BaseDecl &&
"Base type is not incomplete, but has no definition");
2591 assert(CXXBaseDecl &&
"Base type is not a C++ type");
2596 const auto *BaseCSA = CXXBaseDecl->
getAttr<CodeSegAttr>();
2597 const auto *DerivedCSA = Class->getAttr<CodeSegAttr>();
2598 if ((DerivedCSA || BaseCSA) &&
2599 (!BaseCSA || !DerivedCSA || BaseCSA->getName() != DerivedCSA->getName())) {
2600 Diag(Class->getLocation(), diag::err_mismatched_code_seg_base);
2601 Diag(CXXBaseDecl->
getLocation(), diag::note_base_class_specified_here)
2613 Diag(BaseLoc, diag::err_base_class_has_flexible_array_member)
2621 if (FinalAttr *FA = CXXBaseDecl->
getAttr<FinalAttr>()) {
2622 Diag(BaseLoc, diag::err_class_marked_final_used_as_base)
2624 << FA->isSpelledAsSealed();
2631 Class->setInvalidDecl();
2636 Access, TInfo, EllipsisLoc);
2658 Class->setIsParsingBaseSpecifiers();
2666 ? (
unsigned)diag::warn_unknown_attribute_ignored
2667 : (
unsigned)diag::err_base_specifier_attribute)
2668 << AL << AL.getRange();
2684 Class->setInvalidDecl();
2701 auto Decl = Rec->getAsCXXRecordDecl();
2704 for (
const auto &BaseSpec :
Decl->bases()) {
2707 if (Set.insert(
Base).second)
2725 std::map<QualType, CXXBaseSpecifier*, QualTypeOrdering> KnownBaseTypes;
2732 unsigned NumGoodBases = 0;
2733 bool Invalid =
false;
2734 for (
unsigned idx = 0; idx < Bases.size(); ++idx) {
2744 Diag(Bases[idx]->getBeginLoc(), diag::err_duplicate_base_class)
2745 << KnownBase->
getType() << Bases[idx]->getSourceRange();
2754 KnownBase = Bases[idx];
2755 Bases[NumGoodBases++] = Bases[idx];
2760 if (Bases.size() > 1)
2764 const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
2765 if (Class->isInterface() &&
2776 Class->addAttr(WeakAttr::CreateImplicit(
Context));
2782 Class->setBases(Bases.data(), NumGoodBases);
2785 for (
unsigned idx = 0; idx < NumGoodBases; ++idx) {
2787 QualType BaseType = Bases[idx]->getType();
2797 if (IndirectBaseTypes.count(CanonicalBase)) {
2801 = Class->isDerivedFrom(CanonicalBase->getAsCXXRecordDecl(), Paths);
2805 if (Paths.isAmbiguous(CanonicalBase))
2806 Diag(Bases[idx]->getBeginLoc(), diag::warn_inaccessible_base_class)
2808 << Bases[idx]->getSourceRange();
2810 assert(Bases[idx]->isVirtual());
2826 if (!ClassDecl || Bases.empty())
2887 for (
unsigned I = Path.size(); I != 0; --I) {
2888 if (Path[I - 1].
Base->isVirtual()) {
2895 for (
unsigned I = Start, E = Path.size(); I != E; ++I)
2902 assert(BasePathArray.empty() &&
"Base path array must be empty!");
2903 assert(Paths.isRecordingPaths() &&
"Must record paths!");
2920 unsigned InaccessibleBaseID,
2921 unsigned AmbiguousBaseConvID,
2925 bool IgnoreAccess) {
2933 if (!DerivationOkay)
2938 Path = &Paths.front();
2945 if (PossiblePath.size() == 1) {
2946 Path = &PossiblePath;
2947 if (AmbiguousBaseConvID)
2948 Diag(Loc, diag::ext_ms_ambiguous_direct_base)
2949 <<
Base << Derived << Range;
2956 if (!IgnoreAccess) {
2975 if (AmbiguousBaseConvID) {
2983 Paths.setRecordingPaths(
true);
2985 assert(StillOkay &&
"Can only be used with a derived-to-base conversion");
2994 Diag(Loc, AmbiguousBaseConvID)
2995 << Derived <<
Base << PathDisplayStr << Range << Name;
3004 bool IgnoreAccess) {
3006 Derived,
Base, diag::err_upcast_to_inaccessible_base,
3007 diag::err_ambiguous_derived_to_base_conv, Loc, Range,
DeclarationName(),
3008 BasePath, IgnoreAccess);
3026 std::set<unsigned> DisplayedPaths;
3028 Path != Paths.end(); ++Path) {
3029 if (DisplayedPaths.insert(Path->back().SubobjectNumber).second) {
3032 PathDisplayStr +=
"\n ";
3034 for (CXXBasePath::const_iterator Element = Path->begin();
3035 Element != Path->end(); ++Element)
3036 PathDisplayStr +=
" -> " + Element->Base->getType().getAsString();
3040 return PathDisplayStr;
3051 assert(Access !=
AS_none &&
"Invalid kind for syntactic access specifier!");
3081 if (!OverloadedMethods.empty()) {
3082 if (OverrideAttr *OA = D->
getAttr<OverrideAttr>()) {
3083 Diag(OA->getLocation(),
3084 diag::override_keyword_hides_virtual_member_function)
3085 <<
"override" << (OverloadedMethods.size() > 1);
3086 }
else if (FinalAttr *FA = D->
getAttr<FinalAttr>()) {
3087 Diag(FA->getLocation(),
3088 diag::override_keyword_hides_virtual_member_function)
3089 << (FA->isSpelledAsSealed() ?
"sealed" :
"final")
3090 << (OverloadedMethods.size() > 1);
3101 if (OverrideAttr *OA = D->
getAttr<OverrideAttr>()) {
3102 Diag(OA->getLocation(),
3103 diag::override_keyword_only_allowed_on_virtual_member_functions)
3107 if (FinalAttr *FA = D->
getAttr<FinalAttr>()) {
3108 Diag(FA->getLocation(),
3109 diag::override_keyword_only_allowed_on_virtual_member_functions)
3110 << (FA->isSpelledAsSealed() ?
"sealed" :
"final")
3122 if (MD->
hasAttr<OverrideAttr>() && !HasOverriddenMethods)
3123 Diag(MD->
getLocation(), diag::err_function_marked_override_not_overriding)
3136 if (
const auto *AddIRAttr = MD->
getAttr<SYCLAddIRAttributesFunctionAttr>()) {
3138 Diag(AddIRAttr->getLoc(), diag::err_disallow_attribute_on_func)
3161 auto EmitDiag = [&](
unsigned DiagInconsistent,
unsigned DiagSuggest) {
3170 if (isa<CXXDestructorDecl>(MD))
3172 diag::warn_inconsistent_destructor_marked_not_override_overriding,
3173 diag::warn_suggest_destructor_marked_not_override_overriding);
3175 EmitDiag(diag::warn_inconsistent_function_marked_not_override_overriding,
3176 diag::warn_suggest_function_marked_not_override_overriding);
3185 FinalAttr *FA = Old->
getAttr<FinalAttr>();
3191 << FA->isSpelledAsSealed();
3200 return !RD->isCompleteDefinition() ||
3201 !RD->hasTrivialDefaultConstructor() ||
3202 !RD->hasTrivialDestructor();
3208 llvm::find_if(list, [](
const ParsedAttr &AL) {
3211 if (Itr != list.
end())
3225 std::map<CXXRecordDecl*, NamedDecl*> Bases;
3228 const auto Base =
Specifier->getType()->getAsCXXRecordDecl();
3230 if (Bases.find(
Base) != Bases.end())
3232 for (
const auto Field :
Base->lookup(FieldName)) {
3233 if ((isa<FieldDecl>(Field) || isa<IndirectFieldDecl>(Field)) &&
3236 assert(Bases.find(
Base) == Bases.end());
3249 for (
const auto &
P : Paths) {
3250 auto Base =
P.back().Base->getType()->getAsCXXRecordDecl();
3251 auto It = Bases.find(
Base);
3253 if (It == Bases.end())
3255 auto BaseField = It->second;
3256 assert(BaseField->getAccess() !=
AS_private);
3259 Diag(Loc, diag::warn_shadow_field)
3260 << FieldName << RD <<
Base << DeclIsField;
3261 Diag(BaseField->getLocation(), diag::note_shadow_field);
3286 Expr *BitWidth =
static_cast<Expr*
>(BW);
3295 if (cast<CXXRecordDecl>(
CurContext)->isInterface()) {
3299 unsigned InvalidDecl;
3300 bool ShowDeclName =
true;
3310 else switch (Name.getNameKind()) {
3313 ShowDeclName =
false;
3318 ShowDeclName =
false;
3333 Diag(Loc, diag::err_invalid_member_in_interface)
3334 << (InvalidDecl-1) << Name;
3336 Diag(Loc, diag::err_invalid_member_in_interface)
3337 << (InvalidDecl-1) <<
"";
3363 diag::err_storageclass_invalid_for_member);
3383 const char *PrevSpec;
3388 assert(!Failed &&
"Making a constexpr member const shouldn't fail");
3392 const char *PrevSpec;
3398 "This is the only DeclSpec that should fail to be applied");
3402 isInstField =
false;
3412 if (!Name.isIdentifier()) {
3413 Diag(Loc, diag::err_bad_variable_name)
3422 if (TemplateParameterLists.size()) {
3424 if (TemplateParams->
size()) {
3433 diag::err_template_member_noparams)
3468 if (MSPropertyAttr) {
3470 BitWidth, InitStyle, AS, *MSPropertyAttr);
3473 isInstField =
false;
3476 BitWidth, InitStyle, AS);
3481 CheckShadowInheritedFields(Loc, Name, cast<CXXRecordDecl>(
CurContext));
3489 if (
Member->isInvalidDecl()) {
3491 }
else if (isa<VarDecl>(
Member) || isa<VarTemplateDecl>(
Member)) {
3494 Diag(Loc, diag::err_static_not_bitfield)
3496 }
else if (isa<TypedefDecl>(
Member)) {
3498 Diag(Loc, diag::err_typedef_not_bitfield)
3503 Diag(Loc, diag::err_not_integral_type_bitfield)
3504 << Name << cast<ValueDecl>(
Member)->getType()
3509 Member->setInvalidDecl();
3514 NonTemplateMember = FunTmpl->getTemplatedDecl();
3516 NonTemplateMember = VarTmpl->getTemplatedDecl();
3522 if (NonTemplateMember !=
Member)
3528 if (
auto *DG = dyn_cast<CXXDeductionGuideDecl>(NonTemplateMember)) {
3529 auto *TD = DG->getDeducedTemplate();
3532 if (AS != TD->getAccess() &&
3533 TD->getDeclContext()->getRedeclContext()->Equals(
3534 DG->getDeclContext()->getRedeclContext())) {
3535 Diag(DG->getBeginLoc(), diag::err_deduction_guide_wrong_access);
3536 Diag(TD->getBeginLoc(), diag::note_deduction_guide_template_access)
3539 for (
const auto *D : cast<CXXRecordDecl>(
CurContext)->decls()) {
3540 if (
const auto *AccessSpec = dyn_cast<AccessSpecDecl>(D))
3541 LastAccessSpec = AccessSpec;
3543 assert(LastAccessSpec &&
"differing access with no access specifier");
3544 Diag(LastAccessSpec->
getBeginLoc(), diag::note_deduction_guide_access)
3554 Member->addAttr(FinalAttr::Create(
3567 assert((Name || isInstField) &&
"No identifier for non-field ?");
3589 if (isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(
3590 Value->getType()) &&
3592 Diag(Loc, diag::err_sycl_device_global_not_publicly_accessible)
3602 class UninitializedFieldVisitor
3607 llvm::SmallPtrSetImpl<ValueDecl*> &Decls;
3610 llvm::SmallPtrSetImpl<QualType> &BaseClasses;
3625 UninitializedFieldVisitor(
Sema &S,
3626 llvm::SmallPtrSetImpl<ValueDecl*> &Decls,
3627 llvm::SmallPtrSetImpl<QualType> &BaseClasses)
3628 : Inherited(S.
Context), S(S), Decls(Decls), BaseClasses(BaseClasses),
3629 Constructor(nullptr), InitList(
false), InitListFieldDecl(nullptr) {}
3632 bool IsInitListMemberExprInitialized(
MemberExpr *ME,
3633 bool CheckReferenceOnly) {
3635 bool ReferenceField =
false;
3640 Fields.push_back(FD);
3642 ReferenceField =
true;
3648 if (CheckReferenceOnly && !ReferenceField)
3654 for (
const FieldDecl *FD : llvm::drop_begin(llvm::reverse(Fields)))
3657 for (
auto UsedIter = UsedFieldIndex.begin(),
3658 UsedEnd = UsedFieldIndex.end(),
3659 OrigIter = InitFieldIndex.begin(),
3660 OrigEnd = InitFieldIndex.end();
3661 UsedIter != UsedEnd && OrigIter != OrigEnd; ++UsedIter, ++OrigIter) {
3662 if (*UsedIter < *OrigIter)
3664 if (*UsedIter > *OrigIter)
3671 void HandleMemberExpr(
MemberExpr *ME,
bool CheckReferenceOnly,
3684 dyn_cast<MemberExpr>(
Base->IgnoreParenImpCasts())) {
3686 if (isa<VarDecl>(SubME->getMemberDecl()))
3689 if (
FieldDecl *FD = dyn_cast<FieldDecl>(SubME->getMemberDecl()))
3694 AllPODFields =
false;
3696 Base = SubME->getBase();
3699 if (!isa<CXXThisExpr>(
Base->IgnoreParenImpCasts())) {
3704 if (AddressOf && AllPODFields)
3710 while (isa<ImplicitCastExpr>(BaseCast->getSubExpr())) {
3711 BaseCast = cast<ImplicitCastExpr>(BaseCast->getSubExpr());
3714 if (BaseCast->getCastKind() == CK_UncheckedDerivedToBase) {
3724 if (!Decls.count(FoundVD))
3729 if (InitList && !AddressOf && FoundVD == InitListFieldDecl) {
3731 if (IsInitListMemberExprInitialized(ME, CheckReferenceOnly)) {
3736 if (CheckReferenceOnly && !IsReference)
3740 unsigned diag = IsReference
3741 ? diag::warn_reference_field_is_uninit
3742 : diag::warn_field_is_uninit;
3746 diag::note_uninit_in_this_constructor)
3751 void HandleValue(
Expr *E,
bool AddressOf) {
3754 if (
MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
3755 HandleMemberExpr(ME,
false ,
3761 Visit(CO->getCond());
3762 HandleValue(CO->getTrueExpr(), AddressOf);
3763 HandleValue(CO->getFalseExpr(), AddressOf);
3768 dyn_cast<BinaryConditionalOperator>(E)) {
3769 Visit(BCO->getCond());
3770 HandleValue(BCO->getFalseExpr(), AddressOf);
3775 HandleValue(OVE->getSourceExpr(), AddressOf);
3780 switch (BO->getOpcode()) {
3785 HandleValue(BO->getLHS(), AddressOf);
3786 Visit(BO->getRHS());
3789 Visit(BO->getLHS());
3790 HandleValue(BO->getRHS(), AddressOf);
3799 InitFieldIndex.push_back(0);
3800 for (
auto Child : ILE->
children()) {
3801 if (
InitListExpr *SubList = dyn_cast<InitListExpr>(Child)) {
3802 CheckInitListExpr(SubList);
3806 ++InitFieldIndex.back();
3808 InitFieldIndex.pop_back();
3817 DeclsToRemove.clear();
3824 InitListFieldDecl =
Field;
3825 InitFieldIndex.clear();
3826 CheckInitListExpr(ILE);
3840 HandleMemberExpr(ME,
true ,
false );
3849 Inherited::VisitImplicitCastExpr(E);
3855 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(ArgExpr))
3859 if (ICE->getCastKind() == CK_NoOp)
3860 ArgExpr = ICE->getSubExpr();
3861 HandleValue(ArgExpr,
false );
3864 Inherited::VisitCXXConstructExpr(E);
3869 if (isa<MemberExpr>(Callee)) {
3870 HandleValue(Callee,
false );
3876 Inherited::VisitCXXMemberCallExpr(E);
3882 HandleValue(E->
getArg(0),
false);
3886 Inherited::VisitCallExpr(E);
3892 if (isa<UnresolvedLookupExpr>(Callee))
3893 return Inherited::VisitCXXOperatorCallExpr(E);
3897 HandleValue(Arg->IgnoreParenImpCasts(),
false );
3907 DeclsToRemove.push_back(FD);
3910 HandleValue(E->
getLHS(),
false );
3915 Inherited::VisitBinaryOperator(E);
3925 HandleValue(ME->
getBase(),
true );
3930 Inherited::VisitUnaryOperator(E);
3940 static void DiagnoseUninitializedFields(
3960 for (
auto *I : RD->
decls()) {
3961 if (
auto *FD = dyn_cast<FieldDecl>(I)) {
3962 UninitializedFields.insert(FD);
3963 }
else if (
auto *IFD = dyn_cast<IndirectFieldDecl>(I)) {
3964 UninitializedFields.insert(IFD->getAnonField());
3969 for (
auto I : RD->
bases())
3970 UninitializedBaseClasses.insert(I.getType().getCanonicalType());
3972 if (UninitializedFields.empty() && UninitializedBaseClasses.empty())
3975 UninitializedFieldVisitor UninitializedChecker(SemaRef,
3976 UninitializedFields,
3977 UninitializedBaseClasses);
3979 for (
const auto *FieldInit :
Constructor->inits()) {
3980 if (UninitializedFields.empty() && UninitializedBaseClasses.empty())
3983 Expr *InitExpr = FieldInit->getInit();
3988 dyn_cast<CXXDefaultInitExpr>(InitExpr)) {
3989 InitExpr =
Default->getExpr();
3993 UninitializedChecker.CheckInitializer(InitExpr, Constructor,
3994 FieldInit->getAnyMember(),
3995 FieldInit->getBaseClass());
3997 UninitializedChecker.CheckInitializer(InitExpr,
nullptr,
3998 FieldInit->getAnyMember(),
3999 FieldInit->getBaseClass());
4022 auto *ParamDecl = cast<NamedDecl>(Param.Param);
4023 if (ParamDecl->getDeclName())
4044 return ConstraintExpr;
4058 "must set init style when field is created");
4084 Init = Seq.
Perform(*
this, Entity,
Kind, InitExpr);
4085 if (Init.isInvalid()) {
4095 if (Init.isInvalid()) {
4100 InitExpr = Init.get();
4114 DirectBaseSpec =
nullptr;
4115 for (
const auto &
Base : ClassDecl->
bases()) {
4119 DirectBaseSpec = &
Base;
4127 VirtualBaseSpec =
nullptr;
4128 if (!DirectBaseSpec || !DirectBaseSpec->
isVirtual()) {
4137 Path != Paths.end(); ++Path) {
4138 if (Path->back().Base->isVirtual()) {
4139 VirtualBaseSpec = Path->back().Base;
4146 return DirectBaseSpec || VirtualBaseSpec;
4161 DS, IdLoc, InitList,
4180 DS, IdLoc, List, EllipsisLoc);
4189 explicit MemInitializerValidatorCCC(
CXXRecordDecl *ClassDecl)
4190 : ClassDecl(ClassDecl) {}
4192 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
4194 if (
FieldDecl *Member = dyn_cast<FieldDecl>(ND))
4195 return Member->getDeclContext()->getRedeclContext()->Equals(ClassDecl);
4196 return isa<TypeDecl>(ND);
4201 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
4202 return std::make_unique<MemInitializerValidatorCCC>(*
this);
4217 for (
auto *D : ClassDecl->
lookup(MemberOrBase))
4218 if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D))
4219 return cast<ValueDecl>(D);
4246 = dyn_cast<CXXConstructorDecl>(ConstructorD);
4270 ClassDecl, SS, TemplateTypeTy, MemberOrBase)) {
4272 Diag(EllipsisLoc, diag::err_pack_expansion_member_init)
4274 <<
SourceRange(IdLoc, Init->getSourceRange().getEnd());
4282 if (TemplateTypeTy) {
4303 bool NotUnknownSpecialization =
false;
4305 if (
CXXRecordDecl *Record = dyn_cast_or_null<CXXRecordDecl>(DC))
4306 NotUnknownSpecialization = !Record->hasAnyDependentBases();
4308 if (!NotUnknownSpecialization) {
4313 *MemberOrBase, IdLoc);
4333 MemInitializerValidatorCCC CCC(ClassDecl);
4342 PDiag(diag::err_mem_init_not_member_or_class_suggest)
4343 << MemberOrBase <<
true);
4350 DirectBaseSpec, VirtualBaseSpec)) {
4355 PDiag(diag::err_mem_init_not_member_or_class_suggest)
4356 << MemberOrBase <<
false,
4369 if (!TyD && BaseType.
isNull()) {
4370 Diag(IdLoc, diag::err_mem_init_not_member_or_class)
4371 << MemberOrBase <<
SourceRange(IdLoc,Init->getSourceRange().getEnd());
4402 assert((DirectMember || IndirectMember) &&
4403 "Member must be a FieldDecl or IndirectFieldDecl");
4408 if (
Member->isInvalidDecl())
4412 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
4413 Args =
MultiExprArg(ParenList->getExprs(), ParenList->getNumExprs());
4414 }
else if (
InitListExpr *InitList = dyn_cast<InitListExpr>(Init)) {
4415 Args =
MultiExprArg(InitList->getInits(), InitList->getNumInits());
4423 if (
Member->getType()->isDependentType() || Init->isTypeDependent()) {
4428 bool InitList =
false;
4429 if (isa<InitListExpr>(Init)) {
4441 IdLoc, Init->getBeginLoc(), Init->getEndLoc())
4465 Init = MemberInit.
get();
4485 return Diag(NameLoc, diag::err_delegating_ctor)
4487 Diag(NameLoc, diag::warn_cxx98_compat_delegating_ctor);
4489 bool InitList =
true;
4491 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
4493 Args =
MultiExprArg(ParenList->getExprs(), ParenList->getNumExprs());
4502 NameLoc, Init->getBeginLoc(), Init->getEndLoc())
4510 cast<CXXConstructExpr>(DelegationInit.
get())->getConstructor()) &&
4511 "Delegating constructor with no target?");
4517 DelegationInit.
get(), InitRange.
getBegin(),
false);
4535 DelegationInit = Init;
4551 return Diag(BaseLoc, diag::err_base_init_does_not_name_class)
4571 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
4600 if (!DirectBaseSpec && !VirtualBaseSpec) {
4609 return Diag(BaseLoc, diag::err_not_direct_base_or_virtual)
4621 InitRange.
getEnd(), EllipsisLoc);
4628 if (DirectBaseSpec && VirtualBaseSpec)
4629 return Diag(BaseLoc, diag::err_base_init_direct_and_virtual)
4634 BaseSpec = VirtualBaseSpec;
4637 bool InitList =
true;
4639 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
4641 Args =
MultiExprArg(ParenList->getExprs(), ParenList->getNumExprs());
4681 InitRange.
getEnd(), EllipsisLoc);
4691 TargetType, ExprLoc);
4711 bool IsInheritedVirtualBase,
4715 IsInheritedVirtualBase);
4719 switch (ImplicitInitKind) {
4725 BaseInit = InitSeq.
Perform(SemaRef, InitEntity, InitKind, None);
4731 bool Moving = ImplicitInitKind ==
IIK_Move;
4732 ParmVarDecl *Param = Constructor->getParamDecl(0);
4738 Constructor->getLocation(), ParamType,
4753 BasePath.push_back(BaseSpec);
4755 CK_UncheckedDerivedToBase,
4763 BaseInit = InitSeq.
Perform(SemaRef, InitEntity, InitKind, CopyCtorArg);
4786 ValueDecl *Referenced = cast<MemberExpr>(MemRef)->getMemberDecl();
4795 if (Field->isInvalidDecl())
4801 bool Moving = ImplicitInitKind ==
IIK_Move;
4802 ParmVarDecl *Param = Constructor->getParamDecl(0);
4806 if (Field->isZeroLengthBitField(SemaRef.
Context))
4809 Expr *MemberExprBase =
4822 LookupResult MemberLookup(SemaRef, Field->getDeclName(), Loc,
4824 MemberLookup.
addDecl(Indirect ? cast<ValueDecl>(Indirect)
4860 InitSeq.Perform(SemaRef, Entity, InitKind,
MultiExprArg(&CtorArgE, 1));
4875 "Unhandled implicit init kind!");
4891 InitSeq.
Perform(SemaRef, InitEntity, InitKind, None);
4911 if (!Field->getParent()->isUnion()) {
4913 SemaRef.
Diag(Constructor->getLocation(),
4914 diag::err_uninitialized_member_in_ctor)
4915 << (
int)Constructor->isImplicit()
4917 << 0 << Field->getDeclName();
4918 SemaRef.
Diag(Field->getLocation(), diag::note_declared_at);
4923 SemaRef.
Diag(Constructor->getLocation(),
4924 diag::err_uninitialized_member_in_ctor)
4925 << (
int)Constructor->isImplicit()
4927 << 1 << Field->getDeclName();
4928 SemaRef.
Diag(Field->getLocation(), diag::note_declared_at);
4945 CXXMemberInit =
nullptr;
4950 struct BaseAndFieldInfo {
4953 bool AnyErrorsInInits;
4955 llvm::DenseMap<const void *, CXXCtorInitializer*> AllBaseFields;
4957 llvm::DenseMap<TagDecl*, FieldDecl*> ActiveUnionMember;
4960 : S(S), Ctor(Ctor), AnyErrorsInInits(ErrorsInInits) {
4972 bool isImplicitCopyOrMove()
const {
4983 llvm_unreachable(
"Invalid ImplicitInitializerKind!");
4987 AllToInit.push_back(Init);
4990 if (Init->getInit()->HasSideEffects(S.
Context))
4996 bool isInactiveUnionMember(
FieldDecl *Field) {
5003 return Active !=
Field->getCanonicalDecl();
5006 if (isImplicitCopyOrMove())
5011 if (
Field->hasInClassInitializer())
5015 if (!
Field->isAnonymousStructOrUnion())
5024 bool isWithinInactiveUnionMember(
FieldDecl *Field,
5027 return isInactiveUnionMember(Field);
5029 for (
auto *C : Indirect->
chain()) {
5031 if (Field && isInactiveUnionMember(Field))
5046 if (!ArrayT->getSize())
5049 T = ArrayT->getElementType();
5058 if (Field->isInvalidDecl())
5063 Info.AllBaseFields.lookup(Field->getCanonicalDecl()))
5064 return Info.addFieldInitializer(Init);
5078 if (Info.isWithinInactiveUnionMember(Field, Indirect))
5081 if (Field->hasInClassInitializer() && !Info.isImplicitCopyOrMove()) {
5099 return Info.addFieldInitializer(Init);
5109 if (Info.AnyErrorsInInits)
5120 return Info.addFieldInitializer(Init);
5127 Constructor->setNumCtorInitializers(1);
5131 Constructor->setCtorInitializers(initializer);
5140 DiagnoseUninitializedFields(*
this, Constructor);
5147 if (Constructor->isDependentContext()) {
5150 if (!Initializers.empty()) {
5151 Constructor->setNumCtorInitializers(Initializers.size());
5154 memcpy(baseOrMemberInitializers, Initializers.data(),
5156 Constructor->setCtorInitializers(baseOrMemberInitializers);
5161 Constructor->setInvalidDecl();
5166 BaseAndFieldInfo Info(*
this, Constructor, AnyErrors);
5170 CXXRecordDecl *ClassDecl = Constructor->getParent()->getDefinition();
5174 bool HadError =
false;
5176 for (
unsigned i = 0; i < Initializers.size(); i++) {
5179 if (
Member->isBaseInitializer())
5182 Info.AllBaseFields[
Member->getAnyMember()->getCanonicalDecl()] =
Member;
5185 for (
auto *C : F->chain()) {
5188 Info.ActiveUnionMember.insert(std::make_pair(
5193 Info.ActiveUnionMember.insert(std::make_pair(
5201 for (
auto &I : ClassDecl->
bases()) {
5203 DirectVBases.insert(&I);
5207 for (
auto &VBase : ClassDecl->
vbases()) {
5209 = Info.AllBaseFields.lookup(VBase.getType()->getAs<
RecordType>())) {
5217 Diag(
Value->getSourceLocation(), diag::warn_abstract_vbase_init_ignored)
5218 << VBase.getType() << ClassDecl;
5222 Info.AllToInit.push_back(
Value);
5223 }
else if (!AnyErrors && !ClassDecl->
isAbstract()) {
5228 bool IsInheritedVirtualBase = !DirectVBases.count(&VBase);
5231 &VBase, IsInheritedVirtualBase,
5237 Info.AllToInit.push_back(CXXBaseInit);
5244 if (
Base.isVirtual())
5248 = Info.AllBaseFields.lookup(
Base.getType()->getAs<
RecordType>())) {
5249 Info.AllToInit.push_back(
Value);
5250 }
else if (!AnyErrors) {
5259 Info.AllToInit.push_back(CXXBaseInit);
5264 for (
auto *Mem : ClassDecl->
decls()) {
5265 if (
auto *F = dyn_cast<FieldDecl>(Mem)) {
5270 if (F->isUnnamedBitfield())
5276 if (F->isAnonymousStructOrUnion() && !Info.isImplicitCopyOrMove())
5285 if (Info.isImplicitCopyOrMove())
5288 if (
auto *F = dyn_cast<IndirectFieldDecl>(Mem)) {
5289 if (F->getType()->isIncompleteArrayType()) {
5291 "Incomplete array type is not valid");
5303 unsigned NumInitializers = Info.AllToInit.size();
5304 if (NumInitializers > 0) {
5305 Constructor->setNumCtorInitializers(NumInitializers);
5308 memcpy(baseOrMemberInitializers, Info.AllToInit.data(),
5310 Constructor->setCtorInitializers(baseOrMemberInitializers);
5315 Constructor->getParent());
5325 for (
auto *Field : RD->
fields())
5330 IdealInits.push_back(Field->getCanonicalDecl());
5339 if (!
Member->isAnyMemberInitializer())
5342 return Member->getAnyMember()->getCanonicalDecl();
5348 if (
Previous->isAnyMemberInitializer())
5353 if (Current->isAnyMemberInitializer())
5354 Diag << 0 << Current->getAnyMember();
5356 Diag << 1 << Current->getTypeSourceInfo()->getType();
5362 if (Constructor->getDeclContext()->isDependentContext())
5367 bool ShouldCheckOrder =
false;
5368 for (
unsigned InitIndex = 0; InitIndex != Inits.size(); ++InitIndex) {
5370 if (!SemaRef.
Diags.
isIgnored(diag::warn_initializer_out_of_order,
5371 Init->getSourceLocation())) {
5372 ShouldCheckOrder =
true;
5376 if (!ShouldCheckOrder)
5387 for (
const auto &VBase : ClassDecl->
vbases())
5391 for (
const auto &
Base : ClassDecl->
bases()) {
5392 if (
Base.isVirtual())
5398 for (
auto *Field : ClassDecl->
fields()) {
5399 if (Field->isUnnamedBitfield())
5405 unsigned NumIdealInits = IdealInitKeys.size();
5406 unsigned IdealIndex = 0;
5415 for (
unsigned InitIndex = 0; InitIndex != Inits.size(); ++InitIndex) {
5420 for (; IdealIndex != NumIdealInits; ++IdealIndex)
5421 if (InitKey == IdealInitKeys[IdealIndex])
5427 if (IdealIndex == NumIdealInits && InitIndex) {
5428 WarnIndexes.push_back(InitIndex);
5431 for (IdealIndex = 0; IdealIndex != NumIdealInits; ++IdealIndex)
5432 if (InitKey == IdealInitKeys[IdealIndex])
5435 assert(IdealIndex < NumIdealInits &&
5436 "initializer not found in initializer list");
5438 CorrelatedInitOrder.emplace_back(IdealIndex, InitIndex);
5441 if (WarnIndexes.empty())
5445 llvm::sort(CorrelatedInitOrder,
5446 [](
auto &LHS,
auto &RHS) {
return LHS.first < RHS.first; });
5452 Inits[WarnIndexes.front() - 1]->getSourceLocation(),
5453 WarnIndexes.size() == 1 ? diag::warn_initializer_out_of_order
5454 : diag::warn_some_initializers_out_of_order);
5456 for (
unsigned I = 0; I < CorrelatedInitOrder.size(); ++I) {
5457 if (CorrelatedInitOrder[I].second == I)
5472 if (WarnIndexes.size() == 1) {
5474 Inits[WarnIndexes.front()]);
5480 for (
unsigned WarnIndex : WarnIndexes) {
5483 diag::note_initializer_out_of_order);
5490 bool CheckRedundantInit(
Sema &S,
5498 if (
FieldDecl *Field = Init->getAnyMember())
5499 S.
Diag(Init->getSourceLocation(),
5500 diag::err_multiple_mem_initialization)
5501 <<
Field->getDeclName()
5502 << Init->getSourceRange();
5504 const Type *BaseClass = Init->getBaseClass();
5505 assert(BaseClass &&
"neither field nor base");
5506 S.
Diag(Init->getSourceLocation(),
5507 diag::err_multiple_base_initialization)
5509 << Init->getSourceRange();
5517 typedef std::pair<NamedDecl *, CXXCtorInitializer *> UnionEntry;
5518 typedef llvm::DenseMap<RecordDecl*, UnionEntry> RedundantUnionMap;
5520 bool CheckRedundantUnionInit(
Sema &S,
5522 RedundantUnionMap &Unions) {
5527 while (
Parent->isAnonymousStructOrUnion() ||
Parent->isUnion()) {
5529 UnionEntry &En = Unions[
Parent];
5530 if (En.first && En.first != Child) {
5531 S.
Diag(Init->getSourceLocation(),
5532 diag::err_multiple_mem_union_initialization)
5533 <<
Field->getDeclName()
5534 << Init->getSourceRange();
5535 S.
Diag(En.second->getSourceLocation(), diag::note_previous_initializer)
5536 << 0 << En.second->getSourceRange();
5543 if (!
Parent->isAnonymousStructOrUnion())
5560 if (!ConstructorDecl)
5566 = dyn_cast<CXXConstructorDecl>(ConstructorDecl);
5569 Diag(ColonLoc, diag::err_only_constructors_take_base_inits);
5576 llvm::DenseMap<const void *, CXXCtorInitializer *> Members;
5579 RedundantUnionMap MemberUnions;
5581 bool HadError =
false;
5582 for (
unsigned i = 0; i < MemInits.size(); i++) {
5586 Init->setSourceOrder(i);
5588 if (Init->isAnyMemberInitializer()) {
5590 if (CheckRedundantInit(*
this, Init, Members[Key]) ||
5591 CheckRedundantUnionInit(*
this, Init, MemberUnions))
5593 }
else if (Init->isBaseInitializer()) {
5595 if (CheckRedundantInit(*
this, Init, Members[Key]))
5598 assert(Init->isDelegatingInitializer());
5600 if (MemInits.size() != 1) {
5601 Diag(Init->getSourceLocation(),
5602 diag::err_delegating_initializer_alone)
5603 << Init->getSourceRange() << MemInits[i ? 0 : 1]->getSourceRange();
5619 DiagnoseUninitializedFields(*
this, Constructor);
5636 for (
auto *Field : ClassDecl->
fields()) {
5637 if (Field->isInvalidDecl())
5660 assert(Dtor &&
"No dtor found for FieldClassDecl!");
5662 PDiag(diag::err_access_dtor_field)
5663 << Field->getDeclName()
5672 bool VisitVirtualBases = !ClassDecl->
isAbstract();
5679 if (Dtor && Dtor->
isUsed())
5680 VisitVirtualBases =
false;
5686 for (
const auto &
Base : ClassDecl->
bases()) {
5692 if (
Base.isVirtual()) {
5693 if (!VisitVirtualBases)
5695 DirectVirtualBases.insert(RT);
5706 assert(Dtor &&
"No dtor found for BaseClassDecl!");
5710 PDiag(diag::err_access_dtor_base)
5711 <<
Base.getType() <<
Base.getSourceRange(),
5718 if (VisitVirtualBases)
5720 &DirectVirtualBases);
5725 llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases) {
5727 for (
const auto &VBase : ClassDecl->
vbases()) {
5732 if (DirectVirtualBases && DirectVirtualBases->count(RT))
5743 assert(Dtor &&
"No dtor found for BaseClassDecl!");
5746 PDiag(diag::err_access_dtor_vbase)
5752 diag::err_access_dtor_vbase, 0, ClassDecl->
getLocation(),
5766 = dyn_cast<CXXConstructorDecl>(CDtorDecl)) {
5768 DiagnoseUninitializedFields(*
this, Constructor);
5823 for (CXXFinalOverriderMap::iterator M = FinalOverriders.begin(),
5824 MEnd = FinalOverriders.end();
5828 SOEnd = M->second.end();
5829 SO != SOEnd; ++SO) {
5836 if (SO->second.size() != 1)
5839 if (!SO->second.front().Method->isPure())
5842 if (!SeenPureMethods.insert(SO->second.front().Method).second)
5845 Diag(SO->second.front().Method->getLocation(),
5846 diag::note_pure_virtual_function)
5847 << SO->second.front().Method->getDeclName() << RD->
getDeclName();
5857 struct AbstractUsageInfo {
5864 : S(S), Record(Record),
5865 AbstractType(S.
Context.getCanonicalType(
5866 S.
Context.getTypeDeclType(Record))),
5870 if (Invalid)
return;
5878 struct CheckAbstractUsage {
5879 AbstractUsageInfo &Info;
5882 CheckAbstractUsage(AbstractUsageInfo &Info,
const NamedDecl *Ctx)
5883 : Info(Info), Ctx(Ctx) {}
5887 #define ABSTRACT_TYPELOC(CLASS, PARENT)
5888 #define TYPELOC(CLASS, PARENT) \
5889 case TypeLoc::CLASS: Check(TL.castAs<CLASS##TypeLoc>(), Sel); break;
5890 #include "clang/AST/TypeLocNodes.def"
5896 for (
unsigned I = 0, E = TL.
getNumParams(); I != E; ++I) {
5911 for (
unsigned I = 0, E = TL.
getNumArgs(); I != E; ++I) {
5921 #define CheckPolymorphic(Type) \
5922 void Check(Type TL, Sema::AbstractDiagSelID Sel) { \
5923 Visit(TL.getNextTypeLoc(), Sema::AbstractNone); \
5938 return Visit(Next, Sel);
5948 T = Info.S.Context.getBaseElementType(T);
5951 if (CT != Info.AbstractType)
return;
5956 Info.S.Diag(Ctx->
getLocation(), diag::err_array_of_abstract_type)
5959 Info.S.Diag(Ctx->
getLocation(), diag::err_abstract_type_in_decl)
5962 Info.DiagnoseAbstractType();
5968 CheckAbstractUsage(*
this, D).Visit(TL, Sel);
6003 for (
auto *D : RD->
decls()) {
6004 if (D->isImplicit())
continue;
6007 if (
auto *FD = dyn_cast<FriendDecl>(D)) {
6008 D = FD->getFriendDecl();
6013 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
6015 }
else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
6019 }
else if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6022 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
6024 }
else if (
auto *VTD = dyn_cast<VarTemplateDecl>(D)) {
6028 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(D)) {
6030 }
else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(D)) {
6041 assert(ClassAttr->
getKind() == attr::DLLExport);
6051 struct MarkingClassDllexported {
6062 ~MarkingClassDllexported() {
6065 } MarkingDllexportedContext(S, Class, ClassAttr->
getLocation());
6072 if (!
Member->hasAttr<DLLExportAttr>())
6077 auto *VD = dyn_cast<VarDecl>(
Member);
6078 if (VD && VD->getStorageClass() ==
SC_Static &&
6082 auto *MD = dyn_cast<CXXMethodDecl>(
Member);
6086 if (MD->isUserProvided()) {
6096 auto *CD = dyn_cast<CXXConstructorDecl>(MD);
6106 }
else if (MD->isExplicitlyDefaulted()) {
6115 }
else if (!MD->isTrivial() ||
6116 MD->isCopyAssignmentOperator() ||
6117 MD->isMoveAssignmentOperator()) {
6141 auto *CD = dyn_cast<CXXConstructorDecl>(
Member);
6142 if (!CD || !CD->isDefaultConstructor())
6144 auto *
Attr = CD->getAttr<DLLExportAttr>();
6150 if (!Class->isDependentContext()) {
6157 if (LastExportedDefaultCtor) {
6159 diag::err_attribute_dll_ambiguous_default_ctor)
6161 S.
Diag(CD->getLocation(), diag::note_entity_declared_at)
6162 << CD->getDeclName();
6165 LastExportedDefaultCtor = CD;
6171 bool ErrorReported =
false;
6172 auto reportIllegalClassTemplate = [&ErrorReported](
Sema &S,
6176 S.
Diag(TD->getLocation(),
6177 diag::err_cuda_device_builtin_surftex_cls_template)
6179 ErrorReported =
true;
6184 auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(Class);
6186 S.
Diag(Class->getLocation(),
6187 diag::err_cuda_device_builtin_surftex_ref_decl)
6189 S.
Diag(Class->getLocation(),
6190 diag::note_cuda_device_builtin_surftex_should_be_template_class)
6194 TD = SD->getSpecializedTemplate();
6198 unsigned N = Params->
size();
6201 reportIllegalClassTemplate(S, TD);
6203 diag::note_cuda_device_builtin_surftex_cls_should_have_n_args)
6206 if (N > 0 && !isa<TemplateTypeParmDecl>(Params->
getParam(0))) {
6207 reportIllegalClassTemplate(S, TD);
6209 diag::note_cuda_device_builtin_surftex_cls_should_have_match_arg)
6213 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->
getParam(1));
6214 if (!NTTP || !NTTP->getType()->isIntegralOrEnumerationType()) {
6215 reportIllegalClassTemplate(S, TD);
6217 diag::note_cuda_device_builtin_surftex_cls_should_have_match_arg)
6225 bool ErrorReported =
false;
6226 auto reportIllegalClassTemplate = [&ErrorReported](
Sema &S,
6230 S.
Diag(TD->getLocation(),
6231 diag::err_cuda_device_builtin_surftex_cls_template)
6233 ErrorReported =
true;
6238 auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(Class);
6240 S.
Diag(Class->getLocation(),
6241 diag::err_cuda_device_builtin_surftex_ref_decl)
6243 S.
Diag(Class->getLocation(),
6244 diag::note_cuda_device_builtin_surftex_should_be_template_class)
6248 TD = SD->getSpecializedTemplate();
6252 unsigned N = Params->
size();
6255 reportIllegalClassTemplate(S, TD);
6257 diag::note_cuda_device_builtin_surftex_cls_should_have_n_args)
6260 if (N > 0 && !isa<TemplateTypeParmDecl>(Params->
getParam(0))) {
6261 reportIllegalClassTemplate(S, TD);
6263 diag::note_cuda_device_builtin_surftex_cls_should_have_match_arg)
6267 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->
getParam(1));
6268 if (!NTTP || !NTTP->getType()->isIntegralOrEnumerationType()) {
6269 reportIllegalClassTemplate(S, TD);
6271 diag::note_cuda_device_builtin_surftex_cls_should_have_match_arg)
6276 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Params->
getParam(2));
6277 if (!NTTP || !NTTP->getType()->isIntegralOrEnumerationType()) {
6278 reportIllegalClassTemplate(S, TD);
6280 diag::note_cuda_device_builtin_surftex_cls_should_have_match_arg)
6288 for (
auto *Method : Class->methods()) {
6289 if (Method->isUserProvided())
6302 if (
auto *Spec = dyn_cast<ClassTemplatePartialSpecializationDecl>(Class)) {
6303 if (
Attr *TemplateAttr =
6304 getDLLAttr(Spec->getSpecializedTemplate()->getTemplatedDecl())) {
6305 auto *A = cast<InheritableAttr>(TemplateAttr->clone(
getASTContext()));
6306 A->setInherited(
true);
6315 if (!Class->isExternallyVisible()) {
6316 Diag(Class->getLocation(), diag::err_attribute_dll_not_extern)
6317 << Class << ClassAttr;
6325 if (!isa<VarDecl>(
Member) && !isa<CXXMethodDecl>(
Member))
6332 diag::err_attribute_dll_member_of_dll_class)
6333 << MemberAttr << ClassAttr;
6334 Diag(ClassAttr->getLocation(), diag::note_previous_attribute);
6335 Member->setInvalidDecl();
6339 if (Class->getDescribedClassTemplate())
6344 const bool ClassExported = ClassAttr->
getKind() == attr::DLLExport;
6349 const bool PropagatedImport =
6351 cast<DLLImportAttr>(ClassAttr)->wasPropagatedToBaseTemplate();
6360 Class->dropAttr<DLLExportAttr>();
6394 auto *Ctor = dyn_cast<CXXConstructorDecl>(MD);
6403 (Ctor || isa<CXXDestructorDecl>(MD)) && MD->
isTrivial())
6410 if (VD && PropagatedImport)
6424 if (ClassExported) {
6436 Member->addAttr(NewAttr);
6446 "friend re-decl should not already have a DLLAttr");
6478 NewAttr->setInherited(
true);
6479 BaseTemplateSpec->
addAttr(NewAttr);
6483 if (
auto *ImportAttr = dyn_cast<DLLImportAttr>(NewAttr))
6484 ImportAttr->setPropagatedToBaseTemplate();
6505 Diag(BaseLoc, diag::warn_attribute_dll_instantiated_base_class)
6510 diag::note_template_class_explicit_specialization_was_here)
6511 << BaseTemplateSpec;
6514 diag::note_template_class_instantiation_was_here)
6515 << BaseTemplateSpec;
6528 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
6540 if (MD->isCopyAssignmentOperator())
6543 if (MD->isMoveAssignmentOperator())
6546 if (isa<CXXDestructorDecl>(FD))
6554 case OO_ExclaimEqual:
6566 case OO_GreaterEqual:
6589 cast<CXXConstructorDecl>(FD));
6607 llvm_unreachable(
"Invalid special member.");
6625 bool CopyCtorIsTrivial =
false, CopyCtorIsTrivialForCall =
false;
6626 bool DtorIsTrivialForCall =
false;
6637 CopyCtorIsTrivial =
true;
6639 CopyCtorIsTrivialForCall =
true;
6643 if (CD->isCopyConstructor() && !CD->isDeleted()) {
6644 if (CD->isTrivial())
6645 CopyCtorIsTrivial =
true;
6646 if (CD->isTrivialForCall())
6647 CopyCtorIsTrivialForCall =
true;
6655 DtorIsTrivialForCall =
true;
6657 if (!DD->isDeleted() && DD->isTrivialForCall())
6658 DtorIsTrivialForCall =
true;
6662 if (CopyCtorIsTrivialForCall && DtorIsTrivialForCall)
6676 uint64_t TypeSize = isAArch64 ? 128 : 64;
6678 if (CopyCtorIsTrivial &&
6688 bool HasNonDeletedCopyOrMove =
false;
6694 HasNonDeletedCopyOrMove =
true;
6701 HasNonDeletedCopyOrMove =
true;
6709 if (MD->isDeleted())
6712 auto *CD = dyn_cast<CXXConstructorDecl>(MD);
6713 if (CD && CD->isCopyOrMoveConstructor())
6714 HasNonDeletedCopyOrMove =
true;
6715 else if (!isa<CXXDestructorDecl>(MD))
6718 if (!MD->isTrivialForCall())
6722 return HasNonDeletedCopyOrMove;
6733 bool IssuedDiagnostic =
false;
6736 if (!IssuedDiagnostic) {
6738 IssuedDiagnostic =
true;
6740 S.
Diag(O->getLocation(), diag::note_overridden_virtual_function);
6743 return IssuedDiagnostic;
6758 AbstractUsageInfo Info(*
this, Record);
6768 bool Complained =
false;
6769 for (
const auto *F : Record->
fields()) {
6770 if (F->hasInClassInitializer() || F->isUnnamedBitfield())
6773 if (F->getType()->isReferenceType() ||
6774 (F->getType().isConstQualified() && F->getType()->isScalarType())) {
6781 Diag(F->getLocation(), diag::note_refconst_member_not_initialized)
6782 << F->getType()->isReferenceType()
6783 << F->getDeclName();
6801 if (((isa<FieldDecl>(D) || isa<UnresolvedUsingValueDecl>(D)) &&
6803 isa<IndirectFieldDecl>(D)) {
6804 Diag((*I)->getLocation(), diag::err_member_name_of_class)
6815 !Record->
hasAttr<FinalAttr>())
6821 if (FinalAttr *FA = Record->
getAttr<FinalAttr>()) {
6823 << FA->isSpelledAsSealed();
6829 if (!Record->
hasAttr<FinalAttr>()) {
6831 if (
const FinalAttr *FA = dtor->getAttr<FinalAttr>()) {
6832 Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
6833 << FA->isSpelledAsSealed()
6836 (FA->isSpelledAsSealed() ?
" sealed" :
" final"));
6838 diag::note_final_dtor_non_final_class_silence)
6845 if (Record->
hasAttr<TrivialABIAttr>())
6850 bool HasTrivialABI = Record->
hasAttr<TrivialABIAttr>();
6863 auto CheckCompletedMemberFunction = [&](
CXXMethodDecl *MD) {
6874 MD->
isDeleted() ? diag::err_deleted_override
6875 : diag::err_non_deleted_override,
6879 if (MD->isDefaulted() && MD->isDeleted())
6888 MD->isConsteval() ? diag::err_consteval_override
6889 : diag::err_non_consteval_override,
6891 return MD->isConsteval() !=
V->isConsteval();
6893 if (MD->isDefaulted() && MD->isDeleted())
6900 auto CheckForDefaultedFunction = [&](
FunctionDecl *FD) ->
bool {
6901 if (!FD || FD->
isInvalidDecl() || !FD->isExplicitlyDefaulted())
6907 DefaultedSecondaryComparisons.push_back(FD);
6917 bool Incomplete = CheckForDefaultedFunction(M);
6926 if (!M->isImplicit() && !M->isUserProvided()) {
6931 M->setTrivialForCall(
6942 M->setTrivialForCall(HasTrivialABI);
6946 if (!M->isInvalidDecl() && M->isExplicitlyDefaulted() &&
6947 M->hasAttr<DLLExportAttr>()) {
6952 M->dropAttr<DLLExportAttr>();
6954 if (M->hasAttr<DLLExportAttr>()) {
6963 if (M->isDefaulted() && M->isConstexpr() && M->size_overridden_methods())
6967 CheckCompletedMemberFunction(M);
6976 CompleteMemberFunction(Dtor);
6978 bool HasMethodWithOverrideControl =
false,
6979 HasOverridingMethodWithoutOverrideControl =
false;
6980 for (
auto *D : Record->
decls()) {
6981 if (
auto *M = dyn_cast<CXXMethodDecl>(D)) {
6989 if (M->hasAttr<OverrideAttr>())
6990 HasMethodWithOverrideControl =
true;
6991 else if (M->size_overridden_methods() > 0)
6992 HasOverridingMethodWithoutOverrideControl =
true;
6995 if (!isa<CXXDestructorDecl>(M))
6996 CompleteMemberFunction(M);
6997 }
else if (
auto *F = dyn_cast<FriendDecl>(D)) {
6998 CheckForDefaultedFunction(
6999 dyn_cast_or_null<FunctionDecl>(F->getFriendDecl()));
7003 if (HasOverridingMethodWithoutOverrideControl) {
7004 bool HasInconsistentOverrideControl = HasMethodWithOverrideControl;
7005 for (
auto *M : Record->
methods())
7010 for (
FunctionDecl *FD : DefaultedSecondaryComparisons) {
7014 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD))
7015 CheckCompletedMemberFunction(MD);
7039 bool ClangABICompat4 =
7068 if (Record->
hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>())
7070 else if (Record->
hasAttr<CUDADeviceBuiltinTextureTypeAttr>())
7086 unsigned FieldQuals,
bool ConstRHS) {
7087 unsigned LHSQuals = 0;
7089 LHSQuals = FieldQuals;
7091 unsigned RHSQuals = FieldQuals;
7112 llvm::DenseMap<CXXRecordDecl *, ConstructorUsingShadowDecl *>
7118 : S(S), UseLoc(UseLoc) {
7119 bool DiagnosedMultipleConstructedBases =
false;
7125 for (
auto *D : Shadow->
redecls()) {
7126 auto *DShadow = cast<ConstructorUsingShadowDecl>(D);
7127 auto *DNominatedBase = DShadow->getNominatedBaseClass();
7128 auto *DConstructedBase = DShadow->getConstructedBaseClass();
7130 InheritedFromBases.insert(
7131 std::make_pair(DNominatedBase->getCanonicalDecl(),
7132 DShadow->getNominatedBaseClassShadowDecl()));
7133 if (DShadow->constructsVirtualBase())
7134 InheritedFromBases.insert(
7135 std::make_pair(DConstructedBase->getCanonicalDecl(),
7136 DShadow->getConstructedBaseClassShadowDecl()));
7138 assert(DNominatedBase == DConstructedBase);
7143 if (!ConstructedBase) {
7144 ConstructedBase = DConstructedBase;
7145 ConstructedBaseIntroducer = D->getIntroducer();
7146 }
else if (ConstructedBase != DConstructedBase &&
7148 if (!DiagnosedMultipleConstructedBases) {
7149 S.
Diag(UseLoc, diag::err_ambiguous_inherited_constructor)
7152 diag::note_ambiguous_inherited_constructor_using)
7154 DiagnosedMultipleConstructedBases =
true;
7156 S.
Diag(D->getIntroducer()->getLocation(),
7157 diag::note_ambiguous_inherited_constructor_using)
7158 << DConstructedBase;
7162 if (DiagnosedMultipleConstructedBases)
7169 std::pair<CXXConstructorDecl *, bool>
7171 auto It = InheritedFromBases.find(
Base->getCanonicalDecl());
7172 if (It == InheritedFromBases.end())
7173 return std::make_pair(
nullptr,
false);
7177 return std::make_pair(
7179 It->second->constructsVirtualBase());
7182 return std::make_pair(Ctor,
false);
7196 if (InheritedCtor) {
7199 Inherited->findConstructorForBase(ClassDecl, InheritedCtor).first;
7201 return BaseCtor->isConstexpr();
7269 if (Ctor && ClassDecl->
isUnion())
7288 for (
const auto &B : ClassDecl->
bases()) {
7290 if (!BaseType)
continue;
7294 InheritedCtor, Inherited))
7305 for (
const auto *F : ClassDecl->
fields()) {
7306 if (F->isInvalidDecl())
7312 CXXRecordDecl *FieldRecDecl = cast<CXXRecordDecl>(RecordTy->getDecl());
7315 ConstArg && !F->isMutable()))
7329 struct ComputingExceptionSpec {
7340 ~ComputingExceptionSpec() {
7359 if (DFK.isSpecialMember())
7361 S, Loc, cast<CXXMethodDecl>(FD), DFK.asSpecialMember(),
nullptr);
7362 if (DFK.isComparison())
7364 DFK.asComparison());
7366 auto *CD = cast<CXXConstructorDecl>(FD);
7367 assert(CD->getInheritedConstructor() &&
7368 "only defaulted functions and inherited constructors have implicit "
7371 S, Loc, CD->getInheritedConstructor().getShadowDecl());
7398 auto ESI = IES.getExceptionSpec();
7428 "not an explicitly-defaulted special member");
7438 bool HadError =
false;
7451 bool ShouldDeleteForTypeMismatch =
false;
7452 unsigned ExpectedParams = 1;
7463 if (DeleteOnTypeMismatch)
7464 ShouldDeleteForTypeMismatch =
true;
7474 bool CanHaveConstParam =
false;
7483 ReturnType =
Type->getReturnType();
7490 Diag(MD->
getLocation(), diag::err_defaulted_special_member_return_type)
7496 if (
Type->getMethodQuals().hasConst() ||
Type->getMethodQuals().hasVolatile()) {
7497 if (DeleteOnTypeMismatch)
7498 ShouldDeleteForTypeMismatch =
true;
7509 bool HasConstParam =
false;
7516 if (DeleteOnTypeMismatch)
7517 ShouldDeleteForTypeMismatch =
true;
7520 diag::err_defaulted_special_member_volatile_param) << CSM;
7525 if (HasConstParam && !CanHaveConstParam) {
7526 if (DeleteOnTypeMismatch)
7527 ShouldDeleteForTypeMismatch =
true;
7530 diag::err_defaulted_special_member_copy_const_param)
7536 diag::err_defaulted_special_member_move_const_param)
7541 }
else if (ExpectedParams) {
7562 : isa<CXXConstructorDecl>(MD))) &&
7566 ? diag::err_incorrect_defaulted_consteval
7567 : diag::err_incorrect_defaulted_constexpr)
7583 if (!
Type->hasExceptionSpec()) {
7592 llvm::makeArrayRef(&ArgType,
7603 if (ShouldDeleteForTypeMismatch) {
7609 if (ShouldDeleteForTypeMismatch && !HadError) {
7611 diag::warn_cxx17_compat_defaulted_method_type_mismatch) << CSM;
7617 Diag(MD->
getLocation(), diag::err_out_of_line_default_deletes) << CSM;
7618 assert(!ShouldDeleteForTypeMismatch &&
"deleted non-first decl");
7640 template<
typename Derived,
typename ResultList,
typename Result,
7642 class DefaultedComparisonVisitor {
7648 : S(S), RD(RD), FD(FD), DCK(DCK) {
7652 Fns.assign(Info->getUnqualifiedLookups().begin(),
7653 Info->getUnqualifiedLookups().end());
7657 ResultList visit() {
7666 llvm_unreachable(
"not a defaulted comparison");
7670 getDerived().visitSubobjects(Results, RD, ParamLvalType.
getQualifiers());
7675 Results.add(getDerived().visitExpandedSubobject(
7676 ParamLvalType, getDerived().getCompleteObject()));
7679 llvm_unreachable(
"");
7683 Derived &getDerived() {
return static_cast<Derived&
>(*this); }
7689 bool visitSubobjects(ResultList &Results,
CXXRecordDecl *Record,
7694 if (Results.add(getDerived().visitSubobject(
7696 getDerived().getBase(&
Base))))
7702 if (
Field->isAnonymousStructOrUnion()) {
7703 if (visitSubobjects(Results,
Field->getType()->getAsCXXRecordDecl(),
7711 if (
Field->isMutable())
7716 if (Results.add(getDerived().visitSubobject(
7717 FieldType, getDerived().getField(Field))))
7725 Result visitSubobject(
QualType Type, Subobject Subobj) {
7728 if (
auto *CAT = dyn_cast_or_null<ConstantArrayType>(AT))
7729 return getDerived().visitSubobjectArray(CAT->getElementType(),
7730 CAT->getSize(), Subobj);
7731 return getDerived().visitExpandedSubobject(
Type, Subobj);
7736 return getDerived().visitSubobject(
Type, Subobj);
7749 struct DefaultedComparisonInfo {
7754 static DefaultedComparisonInfo deleted() {
7755 DefaultedComparisonInfo
Deleted;
7760 bool add(
const DefaultedComparisonInfo &R) {
7770 struct DefaultedComparisonSubobject {
7778 class DefaultedComparisonAnalyzer
7779 :
public DefaultedComparisonVisitor<DefaultedComparisonAnalyzer,
7780 DefaultedComparisonInfo,
7781 DefaultedComparisonInfo,
7782 DefaultedComparisonSubobject> {
7784 enum DiagnosticKind { NoDiagnostics, ExplainDeleted, ExplainConstexpr };
7787 DiagnosticKind Diagnose;
7790 using Base = DefaultedComparisonVisitor;
7791 using Result = DefaultedComparisonInfo;
7792 using Subobject = DefaultedComparisonSubobject;
7798 DiagnosticKind Diagnose = NoDiagnostics)
7799 :
Base(S, RD, FD, DCK), Diagnose(Diagnose) {}
7808 if (Diagnose == ExplainDeleted) {
7812 return Result::deleted();
7815 return Base::visit();
7819 Subobject getCompleteObject() {
7820 return Subobject{Subobject::CompleteObject, RD, FD->
getLocation()};
7824 return Subobject{Subobject::Base,
Base->getType()->getAsCXXRecordDecl(),
7825 Base->getBaseTypeLoc()};
7829 return Subobject{Subobject::Member,
Field,
Field->getLocation()};
7832 Result visitExpandedSubobject(
QualType Type, Subobject Subobj) {
7837 if (Diagnose == ExplainDeleted) {
7838 S.
Diag(Subobj.Loc, diag::note_defaulted_comparison_reference_member)
7841 return Result::deleted();
7846 Expr *Args[] = {&Xi, &Xi};
7850 assert(OO !=
OO_None &&
"not an overloaded operator!");
7851 return visitBinaryOperator(OO, Args, Subobj);
7864 OO, !SpaceshipCandidates));
7869 CandidateSet.exclude(FD);
7871 if (Args[0]->getType()->isOverloadableType())
7882 switch (CandidateSet.BestViableFunction(S, FD->
getLocation(), Best)) {
7890 !Best->RewriteKind) {
7891 if (Diagnose == ExplainDeleted) {
7892 if (Best->Function) {
7893 S.
Diag(Best->Function->getLocation(),
7894 diag::note_defaulted_comparison_not_rewritten_callee)
7897 assert(Best->Conversions.size() == 2 &&
7898 Best->Conversions[0].isUserDefined() &&
7899 "non-user-defined conversion from class to built-in "
7901 S.
Diag(Best->Conversions[0]
7902 .UserDefined.FoundConversionFunction.getDecl()
7904 diag::note_defaulted_comparison_not_rewritten_conversion)
7908 return Result::deleted();
7918 CXXRecordDecl *ArgClass = Args[0]->getType()->getAsCXXRecordDecl();
7919 if (ArgClass && Best->FoundDecl.getDecl() &&
7920 Best->FoundDecl.getDecl()->isCXXClassMember()) {
7921 QualType ObjectType = Subobj.Kind == Subobject::Member
7922 ? Args[0]->getType()
7925 ArgClass, Best->FoundDecl, ObjectType, Subobj.Loc,
7926 Diagnose == ExplainDeleted
7927 ? S.
PDiag(diag::note_defaulted_comparison_inaccessible)
7928 << FD << Subobj.Kind << Subobj.Decl
7930 return Result::deleted();
7933 bool NeedsDeducing =
7941 assert(!BestFD->isDeleted() &&
"wrong overload resolution result");
7943 if (Diagnose == ExplainConstexpr && !BestFD->isConstexpr()) {
7944 if (Subobj.Kind != Subobject::CompleteObject)
7945 S.
Diag(Subobj.Loc, diag::note_defaulted_comparison_not_constexpr)
7946 << Subobj.
Kind << Subobj.Decl;
7947 S.
Diag(BestFD->getLocation(),
7948 diag::note_defaulted_comparison_not_constexpr_here);
7950 return Result::deleted();
7952 R.Constexpr &= BestFD->isConstexpr();
7954 if (NeedsDeducing) {
7959 if (BestFD->getReturnType()->isUndeducedType() &&
7965 if (Diagnose == NoDiagnostics) {
7968 diag::err_defaulted_comparison_cannot_deduce_undeduced_auto)
7969 << Subobj.
Kind << Subobj.Decl;
7972 diag::note_defaulted_comparison_cannot_deduce_undeduced_auto)
7973 << Subobj.
Kind << Subobj.Decl;
7974 S.
Diag(BestFD->getLocation(),
7975 diag::note_defaulted_comparison_cannot_deduce_callee)
7976 << Subobj.
Kind << Subobj.Decl;
7978 return Result::deleted();
7981 BestFD->getCallResultType());
7983 if (Diagnose == ExplainDeleted) {
7984 S.
Diag(Subobj.Loc, diag::note_defaulted_comparison_cannot_deduce)
7985 << Subobj.
Kind << Subobj.Decl
7986 << BestFD->getCallResultType().withoutLocalFastQualifiers();
7987 S.
Diag(BestFD->getLocation(),
7988 diag::note_defaulted_comparison_cannot_deduce_callee)
7989 << Subobj.
Kind << Subobj.Decl;
7991 return Result::deleted();
7993 R.Category = Info->Kind;
7996 QualType T = Best->BuiltinParamTypes[0];
7997 assert(T == Best->BuiltinParamTypes[1] &&
7998 "builtin comparison for different types?");
7999 assert(Best->BuiltinParamTypes[2].isNull() &&
8000 "invalid builtin comparison");
8002 if (NeedsDeducing) {
8005 assert(Cat &&
"no category for builtin comparison?");
8016 if (Diagnose == ExplainDeleted) {
8019 Kind = OO == OO_EqualEqual ? 1 : 2;
8020 CandidateSet.NoteCandidates(
8022 Subobj.Loc, S.
PDiag(diag::note_defaulted_comparison_ambiguous)
8023 << FD <<
Kind << Subobj.Kind << Subobj.Decl),
8026 R = Result::deleted();
8030 if (Diagnose == ExplainDeleted) {
8033 !Best->RewriteKind) {
8034 S.
Diag(Best->Function->getLocation(),
8035 diag::note_defaulted_comparison_not_rewritten_callee)
8039 diag::note_defaulted_comparison_calls_deleted)
8040 << FD << Subobj.
Kind << Subobj.Decl;
8044 R = Result::deleted();
8050 if (OO == OO_Spaceship &&
8054 if (!R.add(visitBinaryOperator(OO_EqualEqual, Args, Subobj,
8056 R.add(visitBinaryOperator(OO_Less, Args, Subobj, &CandidateSet));
8060 if (Diagnose == ExplainDeleted) {
8061 S.
Diag(Subobj.Loc, diag::note_defaulted_comparison_no_viable_function)
8062 << FD << (OO == OO_ExclaimEqual) << Subobj.
Kind << Subobj.Decl;
8066 if (SpaceshipCandidates) {
8067 SpaceshipCandidates->NoteCandidates(
8072 diag::note_defaulted_comparison_no_viable_function_synthesized)
8073 << (OO == OO_EqualEqual ? 0 : 1);
8076 CandidateSet.NoteCandidates(
8081 R = Result::deleted();
8090 struct StmtListResult {
8091 bool IsInvalid =
false;
8095 IsInvalid |= S.isInvalid();
8098 Stmts.push_back(S.get());
8105 class DefaultedComparisonSynthesizer
8106 :
public DefaultedComparisonVisitor<DefaultedComparisonSynthesizer,
8107 StmtListResult, StmtResult,
8108 std::pair<ExprResult, ExprResult>> {
8110 unsigned ArrayDepth = 0;
8113 using Base = DefaultedComparisonVisitor;
8114 using ExprPair = std::pair<ExprResult, ExprResult>;
8121 :
Base(S, RD, FD, DCK), Loc(BodyLoc) {}
8127 StmtListResult Stmts = visit();
8128 if (Stmts.IsInvalid)
8134 llvm_unreachable(
"not a defaulted comparison");
8145 auto OldStmts = std::move(Stmts.Stmts);
8146 Stmts.Stmts.clear();
8149 auto FinishCmp = [&] {
8150 if (
Expr *Prior = CmpSoFar.
get()) {
8152 if (RetVal.
isUnset() && Stmts.Stmts.empty())
8155 else if (Stmts.add(buildIfNotCondReturnFalse(Prior)))
8161 for (
Stmt *EAsStmt : llvm::reverse(OldStmts)) {
8162 Expr *E = dyn_cast<Expr>(EAsStmt);
8165 if (FinishCmp() || Stmts.add(EAsStmt))
8180 std::reverse(Stmts.Stmts.begin(), Stmts.Stmts.end());
8198 RetVal = getDecl(EqualVD);
8201 RetVal = buildStaticCastToR(RetVal.
get());
8207 RetVal = cast<Expr>(Stmts.Stmts.pop_back_val());
8233 ExprPair getCompleteObject() {
8236 if (isa<CXXMethodDecl>(FD)) {
8242 LHS = getParam(Param++);
8250 ExprPair Obj = getCompleteObject();
8251 if (Obj.first.isInvalid() || Obj.second.isInvalid())
8261 ExprPair Obj = getCompleteObject();
8262 if (Obj.first.isInvalid() || Obj.second.isInvalid())
8285 assert(!False.
isInvalid() &&
"should never fail");
8287 if (ReturnFalse.isInvalid())
8305 llvm::raw_svector_ostream
OS(Str);
8306 OS <<
"i" << ArrayDepth;
8317 auto IterRef = [&] {
8321 assert(!Ref.
isInvalid() &&
"can't reference our own variable?");
8327 Loc, BO_NE, IterRef(),
8329 assert(!Cond.
isInvalid() &&
"should never fail");
8333 assert(!Inc.
isInvalid() &&
"should never fail");
8341 Subobj.first = Index(Subobj.first);
8342 Subobj.second = Index(Subobj.second);
8349 if (Substmt.isInvalid())
8355 if (
Expr *ElemCmp = dyn_cast<Expr>(Substmt.get())) {
8357 "should have non-expression statement");
8358 Substmt = buildIfNotCondReturnFalse(ElemCmp);
8359 if (Substmt.isInvalid())
8372 if (Obj.first.isInvalid() || Obj.second.isInvalid())
8380 Obj.second.get(),
true,
8389 llvm_unreachable(
"not a defaulted comparison");
8404 Op = buildStaticCastToR(Op.
get());
8424 if (VDRef.
get()->getType()->isOverloadableType())
8437 VDRef = getDecl(VD);
8456 llvm_unreachable(
"");
8462 assert(!R->
isUndeducedType() &&
"type should have been deduced already");
8493 if (Op == OO_Spaceship) {
8494 Lookup(OO_ExclaimEqual);
8496 Lookup(OO_EqualEqual);
8523 bool IsMethod = isa<CXXMethodDecl>(FD);
8525 auto *MD = cast<CXXMethodDecl>(FD);
8526 assert(!MD->
isStatic() &&
"comparison function cannot be a static member");
8548 FPT->getParamTypes(), EPI));
8556 <<
int(IsMethod) <<
int(DCK);
8562 QualType ParmTy = Param->getType();
8568 bool Ok = !IsMethod;
8573 CTy = Ref->getPointeeType();
8584 }
else if (
auto *CRD = CTy->getAsRecordDecl()) {
8585 RD = cast<CXXRecordDecl>(CRD);
8601 <<
int(DCK) << ParmTy << RefTy <<
int(!IsMethod) << PlainTy
8602 << Param->getSourceRange();
8604 assert(!IsMethod &&
"should know expected type for method");
8606 diag::err_defaulted_comparison_param_unknown)
8607 <<
int(DCK) << ParmTy << Param->getSourceRange();
8613 Diag(FD->
getLocation(), diag::err_defaulted_comparison_param_mismatch)
8615 << ParmTy << Param->getSourceRange();
8620 assert(RD &&
"must have determined class");
8629 diag::err_defaulted_comparison_not_friend,
int(DCK),
8634 return FD->getCanonicalDecl() ==
8635 F->getFriendDecl()->getCanonicalDecl();
8638 <<
int(DCK) <<
int(0) << RD;
8650 Diag(FD->
getLocation(), diag::err_defaulted_comparison_return_type_not_bool)
8663 diag::err_defaulted_comparison_deduced_return_type_not_auto)
8675 DefaultedComparisonInfo Info =
8676 DefaultedComparisonAnalyzer(*
this, RD, FD, DCK).visit();
8692 DefaultedComparisonAnalyzer(*
this, RD, FD, DCK,
8693 DefaultedComparisonAnalyzer::ExplainDeleted)
8702 DefaultedComparisonAnalyzer(*
this, RD, FD, DCK,
8703 DefaultedComparisonAnalyzer::ExplainDeleted)
8739 diag::err_incorrect_defaulted_comparison_constexpr)
8741 DefaultedComparisonAnalyzer(*
this, RD, FD, DCK,
8742 DefaultedComparisonAnalyzer::ExplainConstexpr)
8763 EPI.ExceptionSpec.SourceDecl = FD;
8765 FPT->getParamTypes(), EPI));
8780 EqualEqual->setImplicit();
8795 Scope.addContextNote(UseLoc);
8802 CXXRecordDecl *RD = PT.getNonReferenceType()->getAsCXXRecordDecl();
8806 DefaultedComparisonSynthesizer(*
this, RD, FD, DCK, BodyLoc).build();
8820 L->CompletedImplicitDefinition(FD);
8827 ComputingExceptionSpec CES(S, FD, Loc);
8854 DefaultedComparisonSynthesizer(S, RD, FD, DCK, BodyLoc).build();
8855 if (!Body.isInvalid())
8876 for (
auto &Check : Overriding)
8888 template<
typename Derived>
8889 struct SpecialMemberVisitor {
8896 bool IsConstructor =
false, IsAssignment =
false, ConstArg =
false;
8900 : S(S), MD(MD), CSM(CSM), ICI(ICI) {
8905 IsConstructor =
true;
8909 IsAssignment =
true;
8914 llvm_unreachable(
"invalid special member kind");
8920 ConstArg = RT->getPointeeType().isConstQualified();
8924 Derived &getDerived() {
return static_cast<Derived&
>(*this); }
8927 bool isMove()
const {
8933 unsigned Quals,
bool IsMutable) {
8935 ConstArg && !IsMutable);
8945 cast<CXXConstructorDecl>(MD)->getInheritedConstructor().getConstructor();
8952 typedef llvm::PointerUnion<CXXBaseSpecifier*, FieldDecl*> Subobject;
8959 return B->getBaseTypeLoc();
8961 return Subobj.get<
FieldDecl*>()->getLocation();
8966 VisitNonVirtualBases,
8971 VisitPotentiallyConstructedBases,
8977 bool visit(BasesToVisit Bases) {
8980 if (Bases == VisitPotentiallyConstructedBases)
8981 Bases = RD->
isAbstract() ? VisitNonVirtualBases : VisitAllBases;
8983 for (
auto &B : RD->
bases())
8984 if ((Bases == VisitDirectBases || !B.isVirtual()) &&
8985 getDerived().visitBase(&B))
8988 if (Bases == VisitAllBases)
8989 for (
auto &B : RD->
vbases())
8990 if (getDerived().visitBase(&B))
8993 for (
auto *F : RD->
fields())
8994 if (!F->isInvalidDecl() && !F->isUnnamedBitfield() &&
8995 getDerived().visitField(F))
9004 struct SpecialMemberDeletionInfo
9005 : SpecialMemberVisitor<SpecialMemberDeletionInfo> {
9010 bool AllFieldsAreConst;
9015 : SpecialMemberVisitor(S, MD, CSM, ICI), Diagnose(Diagnose),
9016 Loc(MD->getLocation()), AllFieldsAreConst(
true) {}
9027 bool visitField(
FieldDecl *Field) {
return shouldDeleteForField(Field); }
9030 bool shouldDeleteForField(
FieldDecl *FD);
9031 bool shouldDeleteForAllConstMembers();
9033 bool shouldDeleteForClassSubobject(
CXXRecordDecl *Class, Subobject Subobj,
9035 bool shouldDeleteForSubobjectCall(Subobject Subobj,
9037 bool IsDtorCallInCtor);
9045 bool SpecialMemberDeletionInfo::isAccessible(Subobject Subobj,
9066 bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
9068 bool IsDtorCallInCtor) {
9075 DiagKind = !
Decl ? 0 : 1;
9078 else if (!isAccessible(Subobj,
Decl))
9080 else if (!IsDtorCallInCtor && Field &&
Field->getParent()->isUnion() &&
9081 !
Decl->isTrivial()) {
9096 diag::note_deleted_special_member_class_subobject)
9097 << getEffectiveCSM() << MD->
getParent() <<
true
9098 <<
Field << DiagKind << IsDtorCallInCtor <<
false;
9102 diag::note_deleted_special_member_class_subobject)
9103 << getEffectiveCSM() << MD->
getParent() <<
false
9104 <<
Base->getType() << DiagKind << IsDtorCallInCtor
9118 bool SpecialMemberDeletionInfo::shouldDeleteForClassSubobject(
9121 bool IsMutable =
Field &&
Field->isMutable();
9138 Field &&
Field->hasInClassInitializer()) &&
9139 shouldDeleteForSubobjectCall(Subobj, lookupIn(Class, Quals, IsMutable),
9146 if (IsConstructor) {
9149 false,
false,
false,
false,
false);
9150 if (shouldDeleteForSubobjectCall(Subobj, SMOR,
true))
9157 bool SpecialMemberDeletionInfo::shouldDeleteForVariantObjCPtrMember(
9171 auto *ParentClass = cast<CXXRecordDecl>(FD->
getParent());
9173 diag::note_deleted_special_member_class_subobject)
9174 << getEffectiveCSM() << ParentClass <<
true
9175 << FD << 4 <<
false <<
true;
9192 if (
auto *BaseCtor = SMOR.
getMethod()) {
9197 if (BaseCtor->isDeleted() && Diagnose) {
9199 diag::note_deleted_special_member_class_subobject)
9200 << getEffectiveCSM() << MD->
getParent() <<
false
9201 <<
Base->getType() << 1 <<
false
9205 return BaseCtor->isDeleted();
9207 return shouldDeleteForClassSubobject(BaseClass,
Base, 0);
9212 bool SpecialMemberDeletionInfo::shouldDeleteForField(
FieldDecl *FD) {
9216 if (inUnion() && shouldDeleteForVariantObjCPtrMember(FD, FieldType))
9224 S.
Diag(FD->
getLocation(), diag::note_deleted_default_ctor_uninit_field)
9225 << !!ICI << MD->
getParent() << FD << FieldType << 0;
9236 S.
Diag(FD->
getLocation(), diag::note_deleted_default_ctor_uninit_field)
9242 AllFieldsAreConst =
false;
9248 S.
Diag(FD->
getLocation(), diag::note_deleted_copy_ctor_rvalue_reference)
9252 }
else if (IsAssignment) {
9257 << isMove() << MD->
getParent() << FD << FieldType << 0;
9272 if (!inUnion() && FieldRecord->
isUnion() &&
9274 bool AllVariantFieldsAreConst =
true;
9277 for (
auto *UI : FieldRecord->
fields()) {
9280 if (shouldDeleteForVariantObjCPtrMember(&*UI, UnionFieldType))
9284 AllVariantFieldsAreConst =
false;
9287 if (UnionFieldRecord &&
9288 shouldDeleteForClassSubobject(UnionFieldRecord, UI,
9298 diag::note_deleted_default_ctor_all_const)
9309 if (shouldDeleteForClassSubobject(FieldRecord, FD,
9320 bool SpecialMemberDeletionInfo::shouldDeleteForAllConstMembers() {
9324 bool AnyFields =
false;
9326 if ((AnyFields = !F->isUnnamedBitfield()))
9332 diag::note_deleted_default_ctor_all_const)
9382 bool DeletesOnlyMatchingCopy =
9388 if (!Diagnose)
return true;
9391 for (
auto *I : RD->
ctors()) {
9392 if (I->isMoveConstructor()) {
9393 UserDeclaredMove = I;
9397 assert(UserDeclaredMove);
9400 if (!Diagnose)
return true;
9403 for (
auto *I : RD->
methods()) {
9404 if (I->isMoveAssignmentOperator()) {
9405 UserDeclaredMove = I;
9409 assert(UserDeclaredMove);
9412 if (UserDeclaredMove) {
9414 diag::note_deleted_copy_user_declared_move)
9432 OperatorDelete,
false)) {
9439 SpecialMemberDeletionInfo SMI(*
this, MD, CSM, ICI, Diagnose);
9447 if (SMI.visit(SMI.IsAssignment ? SMI.VisitDirectBases
9448 : SMI.VisitPotentiallyConstructedBases))
9451 if (SMI.shouldDeleteForAllConstMembers())
9467 SMI.ConstArg, Diagnose);
9475 assert(DFK &&
"not a defaultable function");
9482 DefaultedComparisonAnalyzer(
9484 DFK.
asComparison(), DefaultedComparisonAnalyzer::ExplainDeleted)
9506 *Selected =
nullptr;
9510 llvm_unreachable(
"not a special member");
9528 for (
auto *CI : RD->
ctors()) {
9529 if (!CI->isDefaultConstructor())
9536 *Selected = DefCtor;
9569 }
else if (!Selected) {
9577 goto NeedOverloadResolution;
9587 }
else if (!Selected) {
9592 goto NeedOverloadResolution;
9596 NeedOverloadResolution:
9624 llvm_unreachable(
"unknown special method kind");
9628 for (
auto *CI : RD->
ctors())
9629 if (!CI->isImplicit())
9633 typedef CXXRecordDecl::specific_decl_iterator<FunctionTemplateDecl> tmpl_iter;
9636 dyn_cast<CXXConstructorDecl>(TI->getTemplatedDecl()))
9666 ConstRHS, TAH, Diagnose ? &Selected :
nullptr))
9674 S.
Diag(SubobjLoc, diag::note_nontrivial_no_def_ctor)
9677 S.
Diag(CD->getLocation(), diag::note_user_declared_ctor);
9678 }
else if (!Selected)
9679 S.
Diag(SubobjLoc, diag::note_nontrivial_no_copy)
9681 else if (Selected->isUserProvided()) {
9683 S.
Diag(Selected->getLocation(), diag::note_nontrivial_user_provided)
9684 <<
Kind << SubType.getUnqualifiedType() << CSM;
9686 S.
Diag(SubobjLoc, diag::note_nontrivial_user_provided)
9687 <<
Kind << SubType.getUnqualifiedType() << CSM;
9688 S.
Diag(Selected->getLocation(), diag::note_declared_at);
9692 S.
Diag(SubobjLoc, diag::note_nontrivial_subobject)
9693 <<
Kind << SubType.getUnqualifiedType() << CSM;
9711 for (
const auto *FI : RD->
fields()) {
9712 if (FI->isInvalidDecl() || FI->isUnnamedBitfield())
9718 if (FI->isAnonymousStructOrUnion()) {
9720 CSM, ConstArg, TAH, Diagnose))
9731 S.
Diag(FI->getLocation(), diag::note_nontrivial_default_member_init)
9742 S.
Diag(FI->getLocation(), diag::note_nontrivial_objc_ownership)
9747 bool ConstRHS = ConstArg && !FI->isMutable();
9776 bool ConstArg =
false;
9821 llvm_unreachable(
"not a special member");
9827 diag::note_nontrivial_default_arg)
9846 for (
const auto &BI : RD->
bases())
9892 for (
const auto *MI : RD->
methods()) {
9893 if (MI->isVirtual()) {
9895 Diag(MLoc, diag::note_nontrivial_has_virtual) << RD << 0;
9900 llvm_unreachable(
"dynamic class with no vbases and no virtual functions");
9908 struct FindHiddenVirtualMethod {
9916 static bool CheckMostOverridenMethods(
9918 const llvm::SmallPtrSetImpl<const CXXMethodDecl *> &Methods) {
9922 if (CheckMostOverridenMethods(O, Methods))
9938 bool foundSameNameMethod =
false;
9945 foundSameNameMethod =
true;
9962 if (!CheckMostOverridenMethods(MD, OverridenAndUsingBaseMethods))
9963 overloadedMethods.push_back(MD);
9967 if (foundSameNameMethod)
9968 OverloadedMethods.append(overloadedMethods.begin(),
9969 overloadedMethods.end());
9970 return foundSameNameMethod;
9977 llvm::SmallPtrSetImpl<const CXXMethodDecl *>& Methods) {
9995 FindHiddenVirtualMethod FHVM;
10006 ND = shad->getTargetDecl();
10012 OverloadedMethods = FHVM.OverloadedMethods;
10017 for (
unsigned i = 0, e = OverloadedMethods.size(); i != e; ++i) {
10020 diag::note_hidden_overloaded_virtual_declared_here) << overloadedMD;
10037 if (!OverloadedMethods.empty()) {
10039 << MD << (OverloadedMethods.size() > 1);
10046 auto PrintDiagAndRemoveAttr = [&](
unsigned N) {
10049 Diag(RD.
getAttr<TrivialABIAttr>()->getLocation(),
10050 diag::ext_cannot_use_trivial_abi) << &RD;
10051 Diag(RD.
getAttr<TrivialABIAttr>()->getLocation(),
10052 diag::note_cannot_use_trivial_abi_reason) << &RD << N;
10058 auto HasNonDeletedCopyOrMoveConstructor = [&]() {
10070 if (CD->isCopyOrMoveConstructor() && !CD->isDeleted())
10075 if (!HasNonDeletedCopyOrMoveConstructor()) {
10076 PrintDiagAndRemoveAttr(0);
10082 PrintDiagAndRemoveAttr(1);
10086 for (
const auto &B : RD.
bases()) {
10089 if (!B.getType()->isDependentType() &&
10090 !B.getType()->getAsCXXRecordDecl()->canPassInRegisters()) {
10091 PrintDiagAndRemoveAttr(2);
10095 if (B.isVirtual()) {
10096 PrintDiagAndRemoveAttr(3);
10101 for (
const auto *FD : RD.
fields()) {
10106 PrintDiagAndRemoveAttr(4);
10111 if (!RT->isDependentType() &&
10112 !cast<CXXRecordDecl>(RT->getDecl())->canPassInRegisters()) {
10113 PrintDiagAndRemoveAttr(5);
10128 if (AL.getKind() != ParsedAttr::AT_Visibility)
10131 Diag(AL.getLoc(), diag::warn_attribute_after_definition_ignored) << AL;
10154 FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(Friend->getFriendDecl());
10159 Spaceships.clear();
10165 Spaceships.push_back(FD);
10174 if (
auto *FD = dyn_cast<FunctionDecl>(ND))
10175 if (FD->isExplicitlyDefaulted())
10176 Spaceships.push_back(FD);
10276 DefaultedSpaceships);
10277 for (
auto *FD : DefaultedSpaceships)
10284 llvm::function_ref<
Scope *()> EnterScope) {
10292 DeclContext *LookupDC = dyn_cast<DeclContext>(D);
10295 for (
unsigned i = 0; i < DD->getNumTemplateParameterLists(); ++i)
10296 ParameterLists.push_back(DD->getTemplateParameterList(i));
10300 ParameterLists.push_back(FTD->getTemplateParameters());
10301 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
10305 ParameterLists.push_back(VTD->getTemplateParameters());
10306 else if (
auto *PSD = dyn_cast<VarTemplatePartialSpecializationDecl>(D))
10307 ParameterLists.push_back(PSD->getTemplateParameters());
10309 }
else if (
TagDecl *TD = dyn_cast<TagDecl>(D)) {
10310 for (
unsigned i = 0; i < TD->getNumTemplateParameterLists(); ++i)
10311 ParameterLists.push_back(TD->getTemplateParameterList(i));
10315 ParameterLists.push_back(CTD->getTemplateParameters());
10316 else if (
auto *PSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
10317 ParameterLists.push_back(PSD->getTemplateParameters());
10322 unsigned Count = 0;
10323 Scope *InnermostTemplateScope =
nullptr;
10327 if (Params->size() == 0)
10330 InnermostTemplateScope = EnterScope();
10332 if (Param->getDeclName()) {
10333 InnermostTemplateScope->
AddDecl(Param);
10341 if (InnermostTemplateScope) {
10342 assert(LookupDC &&
"no enclosing DeclContext for template lookup");
10350 if (!RecordD)
return;
10357 if (!RecordD)
return;
10431 bool DiagOccured =
false;
10433 [DiagID, &S, &DiagOccured](
DeclSpec::TQ, StringRef QualName,
10440 DiagOccured =
true;
10518 = dyn_cast<CXXRecordDecl>(Constructor->getDeclContext());
10520 return Constructor->setInvalidDecl();
10527 if (!Constructor->isInvalidDecl() &&
10528 Constructor->hasOneParamOrDefaultArgs() &&
10529 Constructor->getTemplateSpecializationKind() !=
10531 QualType ParamType = Constructor->getParamDecl(0)->getType();
10534 SourceLocation ParamLoc = Constructor->getParamDecl(0)->getLocation();
10535 const char *ConstRef
10536 = Constructor->getParamDecl(0)->getIdentifier() ?
"const &"
10538 Diag(ParamLoc, diag::err_constructor_byvalue_arg)
10543 Constructor->setInvalidDecl();
10554 if (!Destructor->getOperatorDelete() && Destructor->isVirtual()) {
10557 if (!Destructor->isImplicit())
10558 Loc = Destructor->getLocation();
10565 Expr *ThisArg =
nullptr;
10570 if (OperatorDelete->isDestroyingOperatorDelete()) {
10571 QualType ParamType = OperatorDelete->getParamDecl(0)->getType();
10578 ActOnCXXThis(OperatorDelete->getParamDecl(0)->getLocation());
10579 assert(!
This.isInvalid() &&
"couldn't form 'this' expr in dtor?");
10581 if (
This.isInvalid()) {
10584 Diag(Loc, diag::note_implicit_delete_this_in_destructor_here);
10587 ThisArg =
This.get();
10593 Destructor->setOperatorDelete(OperatorDelete, ThisArg);
10616 << DeclaratorType << isa<TypeAliasDecl>(TT->getDecl());
10619 if (TST->isTypeAlias())
10621 << DeclaratorType << 1;
10715 if (
After.isInvalid())
10775 if (Proto->getNumParams() > 0) {
10781 }
else if (Proto->isVariadic()) {
10788 if (Proto->getReturnType() != ConvType) {
10789 bool NeedsTypedef =
false;
10793 bool PastFunctionChunk =
false;
10795 switch (Chunk.Kind) {
10797 if (!PastFunctionChunk) {
10798 if (Chunk.Fun.HasTrailingReturnType) {
10803 PastFunctionChunk =
true;
10808 NeedsTypedef =
true;
10830 auto &&DB =
Diag(Loc, diag::err_conv_function_with_complex_decl);
10831 DB << Before <<
After;
10833 if (!NeedsTypedef) {
10837 if (
After.isInvalid() && ConvTSI) {
10845 }
else if (!Proto->getReturnType()->isDependentType()) {
10846 DB << 1 << Proto->getReturnType();
10848 DB << 2 << Proto->getReturnType();
10859 ConvType = Proto->getReturnType();
10885 ? diag::warn_cxx98_compat_explicit_conversion_functions
10886 : diag::ext_explicit_conversion_functions)
10895 assert(Conversion &&
"Expected to receive a conversion function declaration");
10918 if (ConvType == ClassType)
10923 << ClassType << ConvType;
10926 << ClassType << ConvType;
10931 return ConversionTemplate;
10939 struct BadSpecifierDiagnoser {
10942 ~BadSpecifierDiagnoser() {
10946 template<
typename T>
void check(
SourceLocation SpecLoc, T Spec) {
10950 return check(SpecLoc,
10956 if (!Specifiers.empty()) Specifiers +=
" ";
10957 Specifiers += Spec;
10974 assert(GuidedTemplateDecl &&
"missing template decl for deduction guide");
10982 << GuidedTemplateDecl;
10983 Diag(GuidedTemplateDecl->
getLocation(), diag::note_template_decl_here);
10988 if (DS.hasTypeSpecifier() || DS.getTypeQualifiers() ||
10989 DS.getStorageClassSpecLoc().isValid() || DS.isInlineSpecified() ||
10990 DS.isNoreturnSpecified() || DS.hasConstexprSpecifier()) {
10991 BadSpecifierDiagnoser Diagnoser(
10993 diag::err_deduction_guide_invalid_specifier);
10995 Diagnoser.check(DS.getStorageClassSpecLoc(), DS.getStorageClassSpec());
10996 DS.ClearStorageClassSpecs();
11000 Diagnoser.check(DS.getInlineSpecLoc(),
"inline");
11001 Diagnoser.check(DS.getNoreturnSpecLoc(),
"_Noreturn");
11002 Diagnoser.check(DS.getConstexprSpecLoc(),
"constexpr");
11003 DS.ClearConstexprSpec();
11005 Diagnoser.check(DS.getConstSpecLoc(),
"const");
11006 Diagnoser.check(DS.getRestrictSpecLoc(),
"__restrict");
11007 Diagnoser.check(DS.getVolatileSpecLoc(),
"volatile");
11008 Diagnoser.check(DS.getAtomicSpecLoc(),
"_Atomic");
11009 Diagnoser.check(DS.getUnalignedSpecLoc(),
"__unaligned");
11010 DS.ClearTypeQualifiers();
11012 Diagnoser.check(DS.getTypeSpecComplexLoc(), DS.getTypeSpecComplex());
11013 Diagnoser.check(DS.getTypeSpecSignLoc(), DS.getTypeSpecSign());
11014 Diagnoser.check(DS.getTypeSpecWidthLoc(), DS.getTypeSpecWidth());
11015 Diagnoser.check(DS.getTypeSpecTypeLoc(), DS.getTypeSpecType());
11016 DS.ClearTypeSpecType();
11023 bool FoundFunction =
false;
11029 diag::err_deduction_guide_with_complex_decl)
11033 if (!Chunk.Fun.hasTrailingReturnType()) {
11035 diag::err_deduction_guide_no_trailing_return_type);
11041 ParsedType TrailingReturnType = Chunk.Fun.getTrailingReturnType();
11044 assert(TSI &&
"deduction guide has valid type but invalid return type?");
11045 bool AcceptableReturnType =
false;
11046 bool MightInstantiateToSpecialization =
false;
11049 TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
11050 bool TemplateMatches =
11053 AcceptableReturnType =
true;
11058 MightInstantiateToSpecialization = !(TD && isa<ClassTemplateDecl>(TD) &&
11062 MightInstantiateToSpecialization =
true;
11065 if (!AcceptableReturnType) {
11067 diag::err_deduction_guide_bad_trailing_return_type)
11068 << GuidedTemplate << TSI->
getType()
11069 << MightInstantiateToSpecialization
11075 FoundFunction =
true;
11092 assert(*IsInline != PrevNS->
isInline());
11102 S.
Diag(Loc, diag::warn_inline_namespace_reopened_noninline)
11105 S.
Diag(Loc, diag::err_inline_namespace_mismatch);
11120 bool IsInline = InlineLoc.
isValid();
11121 bool IsInvalid =
false;
11122 bool IsStd =
false;
11123 bool AddToKnown =
false;
11144 PrevNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl);
11148 if (IsInline != PrevNS->
isInline())
11150 &IsInline, PrevNS);
11151 }
else if (PrevDecl) {
11153 Diag(Loc, diag::err_redefinition_different_kind)
11158 }
else if (II->
isStr(
"std") &&
11164 AddToKnown = !IsInline;
11167 AddToKnown = !IsInline;
11181 if (PrevNS && IsInline != PrevNS->
isInline())
11183 &IsInline, PrevNS);
11187 StartLoc, Loc, II, PrevNS);
11195 if (
const VisibilityAttr *
Attr = Namespc->
getAttr<VisibilityAttr>())
11201 KnownNamespaces[Namespc] =
false;
11209 TU->setAnonymousNamespace(Namespc);
11211 cast<NamespaceDecl>(
Parent)->setAnonymousNamespace(Namespc);
11260 return AD->getNamespace();
11261 return dyn_cast_or_null<NamespaceDecl>(D);
11267 NamespaceDecl *Namespc = dyn_cast_or_null<NamespaceDecl>(Dcl);
11268 assert(Namespc &&
"Invalid parameter, expected NamespaceDecl");
11271 if (Namespc->
hasAttr<VisibilityAttr>())
11274 if (DeferredExportedNamespaces.erase(Namespc))
11279 return cast_or_null<CXXRecordDecl>(
11288 return cast_or_null<NamespaceDecl>(
11300 Result.suppressDiagnostics();
11308 enum UnsupportedSTLSelect {
11315 struct InvalidSTLDiagnoser {
11320 QualType operator()(UnsupportedSTLSelect Sel = USS_Other, StringRef Name =
"",
11321 const VarDecl *VD =
nullptr) {
11323 auto D = S.
Diag(Loc, diag::err_std_compare_type_not_supported)
11324 << TyForDiags << ((
int)Sel);
11325 if (Sel == USS_InvalidMember || Sel == USS_MissingMember) {
11326 assert(!Name.empty());
11330 if (Sel == USS_InvalidMember) {
11343 "Looking for comparison category type outside of C++.");
11356 if (Info && FullyCheckedComparisonCategories[
static_cast<unsigned>(
Kind)]) {
11369 Diag(Loc, diag::err_implied_comparison_category_type_not_found)
11370 << NameForDiags << (
int)Usage;
11385 InvalidSTLDiagnoser UnsupportedSTLError{*
this, Loc, TyForDiags(Info)};
11388 return UnsupportedSTLError(USS_NonTrivial);
11393 if (
Base->isEmpty())
11396 return UnsupportedSTLError();
11405 !FIt->getType()->isIntegralOrEnumerationType()) {
11406 return UnsupportedSTLError();
11416 return UnsupportedSTLError(USS_MissingMember, MemName);
11419 assert(VD &&
"should not be null!");
11426 return UnsupportedSTLError(USS_InvalidMember, MemName, VD);
11432 return UnsupportedSTLError();
11439 FullyCheckedComparisonCategories[
static_cast<unsigned>(
Kind)] =
true;
11462 "Looking for std::initializer_list outside of C++.");
11476 dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
11484 Template = dyn_cast_or_null<ClassTemplateDecl>(
11485 TST->getTemplateName().getAsTemplateDecl());
11486 Arguments = TST->getArgs();
11504 if (!isa<TemplateTypeParmDecl>(Params->
getParam(0)))
11516 *Element = Arguments[0].getAsType();
11523 S.
Diag(Loc, diag::err_implied_std_initializer_list_not_found);
11530 S.
Diag(Loc, diag::err_implied_std_initializer_list_not_found);
11535 Result.suppressDiagnostics();
11538 S.
Diag(Found->
getLocation(), diag::err_malformed_std_initializer_list);
11546 !isa<TemplateTypeParmDecl>(Params->
getParam(0))) {
11547 S.
Diag(Template->
getLocation(), diag::err_malformed_std_initializer_list);
11589 case Decl::TranslationUnit:
11591 case Decl::LinkageSpec:
11603 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
11605 return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND);
11609 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
11610 return std::make_unique<NamespaceValidatorCCC>(*
this);
11621 NamespaceValidatorCCC CCC{};
11627 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
11628 Ident->
getName().equals(CorrectedStr);
11630 S.
PDiag(diag::err_using_directive_member_suggest)
11631 << Ident << DC << DroppedSpecifier << SS.
getRange(),
11632 S.
PDiag(diag::note_namespace_defined_here));
11635 S.
PDiag(diag::err_using_directive_suggest) << Ident,
11636 S.
PDiag(diag::note_namespace_defined_here));
11638 R.
addDecl(Corrected.getFoundDecl());
11649 assert(!SS.
isInvalid() &&
"Invalid CXXScopeSpec.");
11650 assert(NamespcName &&
"Invalid NamespcName.");
11651 assert(IdentLoc.
isValid() &&
"Invalid NamespceName location.");
11654 while (S->isTemplateParamScope())
11655 S = S->getParent();
11674 NamespcName->
isStr(
"std")) {
11675 Diag(IdentLoc, diag::ext_using_undefined_std);
11686 assert(NS &&
"expected namespace decl");
11705 CommonAncestor = CommonAncestor->
getParent();
11709 IdentLoc, Named, CommonAncestor);
11713 Diag(IdentLoc, diag::warn_using_directive_in_header);
11718 Diag(IdentLoc, diag::err_expected_namespace_name) << SS.
getRange();
11749 Diag(Name.getBeginLoc(), diag::err_using_requires_qualname);
11753 switch (Name.getKind()) {
11764 Diag(Name.getBeginLoc(),
11766 ? diag::warn_cxx98_compat_using_decl_constructor
11767 : diag::err_using_decl_constructor)
11775 Diag(Name.getBeginLoc(), diag::err_using_decl_destructor) << SS.
getRange();
11779 Diag(Name.getBeginLoc(), diag::err_using_decl_template_id)
11780 <<
SourceRange(Name.TemplateId->LAngleLoc, Name.TemplateId->RAngleLoc);
11784 llvm_unreachable(
"cannot parse qualified deduction guide name");
11795 ? diag::err_access_decl
11796 : diag::warn_access_decl_deprecated)
11807 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
11815 SS, TargetNameInfo, EllipsisLoc, AttrList,
11841 llvm_unreachable(
"unexpected DeclSpec type");
11846 if (
auto *Def = Enum->getDefinition())
11868 TD2->getUnderlyingType());
11872 if (isa<UnresolvedUsingIfExistsDecl>(D1) &&
11873 isa<UnresolvedUsingIfExistsDecl>(D2))
11905 if (
auto *Using = dyn_cast<UsingDecl>(BUD)) {
11909 if (isa<EnumDecl>(OrigDC))
11917 Diag(Using->getLocation(),
11918 diag::err_using_decl_nested_name_specifier_is_current_class)
11919 << Using->getQualifierLoc().getSourceRange();
11921 Using->setInvalidDecl();
11925 Diag(Using->getQualifierLoc().getBeginLoc(),
11926 diag::err_using_decl_nested_name_specifier_is_not_base_class)
11927 << Using->getQualifier() << cast<CXXRecordDecl>(
CurContext)
11928 << Using->getQualifierLoc().getSourceRange();
11930 Using->setInvalidDecl();
11935 if (
Previous.empty())
return false;
11938 if (isa<UsingShadowDecl>(
Target))
11939 Target = cast<UsingShadowDecl>(
Target)->getTargetDecl();
11946 NamedDecl *NonTag =
nullptr, *Tag =
nullptr;
11947 bool FoundEquivalentDecl =
false;
11950 NamedDecl *D = (*I)->getUnderlyingDecl();
11954 if (isa<UsingDecl>(D) || isa<UsingPackDecl>(D) || isa<UsingEnumDecl>(D))
11957 if (
auto *RD = dyn_cast<CXXRecordDecl>(D)) {
11962 !isa<IndirectFieldDecl>(
Target) &&
11963 !isa<UnresolvedUsingValueDecl>(
Target) &&
11972 PrevShadow = Shadow;
11973 FoundEquivalentDecl =
true;
11977 FoundEquivalentDecl =
true;
11981 (isa<TagDecl>(D) ? Tag : NonTag) = D;
11984 if (FoundEquivalentDecl)
11989 if (isa<UnresolvedUsingIfExistsDecl>(
Target) !=
11990 (isa_and_nonnull<UnresolvedUsingIfExistsDecl>(NonTag))) {
11991 if (!NonTag && !Tag)
11994 Diag(
Target->getLocation(), diag::note_using_decl_target);
11995 Diag((NonTag ? NonTag : Tag)->getLocation(),
11996 diag::note_using_decl_conflict);
12025 Diag(
Target->getLocation(), diag::note_using_decl_target);
12033 if (isa<TagDecl>(
Target)) {
12035 if (!Tag)
return false;
12038 Diag(
Target->getLocation(), diag::note_using_decl_target);
12039 Diag(Tag->getLocation(), diag::note_using_decl_conflict);
12045 if (!NonTag)
return false;
12048 Diag(
Target->getLocation(), diag::note_using_decl_target);
12058 for (
auto &B : Derived->
bases())
12059 if (B.getType()->getAsCXXRecordDecl() ==
Base)
12060 return B.isVirtual();
12061 llvm_unreachable(
"not a direct base class");
12070 if (isa<UsingShadowDecl>(
Target)) {
12071 Target = cast<UsingShadowDecl>(
Target)->getTargetDecl();
12072 assert(!isa<UsingShadowDecl>(
Target) &&
"nested shadow declaration");
12076 if (
auto *TargetTD = dyn_cast<TemplateDecl>(
Target))
12077 NonTemplateTarget = TargetTD->getTemplatedDecl();
12080 if (NonTemplateTarget && isa<CXXConstructorDecl>(NonTemplateTarget)) {
12081 UsingDecl *Using = cast<UsingDecl>(BUD);
12082 bool IsVirtualBase =
12084 Using->getQualifier()->getAsRecordDecl());
12138 cast<CXXRecordDecl>(Shadow->
getDeclContext())->removeConversion(Shadow);
12145 S->RemoveDecl(Shadow);
12159 bool &AnyDependentBases) {
12164 CanQualType BaseType =
Base.getType()->getCanonicalTypeUnqualified();
12165 if (CanonicalDesiredBase == BaseType)
12167 if (BaseType->isDependentType())
12168 AnyDependentBases =
true;
12176 UsingValidatorCCC(
bool HasTypenameKeyword,
bool IsInstantiation,
12178 : HasTypenameKeyword(HasTypenameKeyword),
12179 IsInstantiation(IsInstantiation), OldNNS(NNS),
12180 RequireMemberOf(RequireMemberOf) {}
12182 bool ValidateCandidate(
const TypoCorrection &Candidate)
override {
12186 if (!ND || isa<NamespaceDecl>(ND))
12196 if (RequireMemberOf) {
12197 auto *FoundRecord = dyn_cast<CXXRecordDecl>(ND);
12198 if (FoundRecord && FoundRecord->isInjectedClassName()) {
12219 bool AnyDependentBases =
false;
12222 AnyDependentBases) &&
12223 !AnyDependentBases)
12227 if (!RD || RequireMemberOf->isProvablyNotDerivedFrom(RD))
12233 auto *FoundRecord = dyn_cast<CXXRecordDecl>(ND);
12234 if (FoundRecord && FoundRecord->isInjectedClassName())
12238 if (isa<TypeDecl>(ND))
12239 return HasTypenameKeyword || !IsInstantiation;
12241 return !HasTypenameKeyword;
12244 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
12245 return std::make_unique<UsingValidatorCCC>(*
this);
12249 bool HasTypenameKeyword;
12250 bool IsInstantiation;
12289 bool IsUsingIfExists) {
12290 assert(!SS.
isInvalid() &&
"Invalid CXXScopeSpec.");
12292 assert(IdentLoc.
isValid() &&
"Invalid TargetName location.");
12301 if (
auto *RD = dyn_cast<CXXRecordDecl>(
CurContext))
12314 assert(IsInstantiation &&
"no scope in non-instantiation");
12342 Diag(UsingLoc, diag::err_using_if_exists_on_ctor);
12348 if (!LookupContext || EllipsisLoc.
isValid()) {
12352 SS, NameInfo, IdentLoc))
12355 if (HasTypenameKeyword) {
12358 UsingLoc, TypenameLoc,
12360 IdentLoc, NameInfo.
getName(),
12364 QualifierLoc, NameInfo, EllipsisLoc);
12372 auto Build = [&](
bool Invalid) {
12375 UsingName, HasTypenameKeyword);
12382 auto BuildInvalid = [&]{
return Build(
true); };
12383 auto BuildValid = [&]{
return Build(
false); };
12386 return BuildInvalid();
12395 if (!IsInstantiation)
12412 if (R.
empty() && IsUsingIfExists)
12429 isa<TranslationUnitDecl>(LookupContext) &&
12432 UsingValidatorCCC CCC(HasTypenameKeyword, IsInstantiation, SS.
getScopeRep(),
12440 << NameInfo.
getName() << LookupContext << 0
12445 NamedDecl *ND = Corrected.getCorrectionDecl();
12447 return BuildInvalid();
12450 auto *RD = dyn_cast<CXXRecordDecl>(ND);
12453 RD = cast<CXXRecordDecl>(RD->
getParent());
12456 if (Corrected.WillReplaceSpecifier()) {
12458 Builder.MakeTrivial(
Context, Corrected.getCorrectionSpecifier(),
12460 QualifierLoc = Builder.getWithLocInContext(
Context);
12465 auto *CurClass = cast<CXXRecordDecl>(
CurContext);
12479 Diag(IdentLoc, diag::err_no_member)
12481 return BuildInvalid();
12486 return BuildInvalid();
12488 if (HasTypenameKeyword) {
12492 Diag(IdentLoc, diag::err_using_typename_non_type);
12494 Diag((*I)->getUnderlyingDecl()->getLocation(),
12495 diag::note_using_decl_target);
12496 return BuildInvalid();
12503 Diag(IdentLoc, diag::err_using_dependent_value_is_type);
12505 return BuildInvalid();
12512 Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_namespace)
12514 return BuildInvalid();
12543 bool Invalid =
false;
12555 if (UED->getEnumDecl() == ED) {
12556 Diag(UsingLoc, diag::err_using_enum_decl_redeclaration)
12568 EnumLoc, NameLoc, ED);
12595 assert(isa<UnresolvedUsingValueDecl>(InstantiatedFrom) ||
12596 isa<UnresolvedUsingTypenameDecl>(InstantiatedFrom) ||
12597 isa<UsingPackDecl>(InstantiatedFrom));
12601 UPD->setAccess(InstantiatedFrom->
getAccess());
12608 assert(!UD->
hasTypename() &&
"expecting a constructor name");
12611 assert(SourceType &&
12612 "Using decl naming constructor doesn't have type in scope spec.");
12616 bool AnyDependentBases =
false;
12618 AnyDependentBases);
12619 if (!
Base && !AnyDependentBases) {
12621 diag::err_using_decl_constructor_not_in_direct_base)
12623 <<
QualType(SourceType, 0) << TargetClass;
12629 Base->setInheritConstructors();
12638 bool HasTypenameKeyword,
12657 if (Qual->
isDependent() && !HasTypenameKeyword) {
12658 for (
auto *D : Prev) {
12659 if (!isa<TypeDecl>(D) && !isa<UsingDecl>(D) && !isa<UsingPackDecl>(D)) {
12660 bool OldCouldBeEnumerator =
12661 isa<UnresolvedUsingValueDecl>(D) || isa<EnumConstantDecl>(D);
12663 OldCouldBeEnumerator ? diag::err_redefinition
12664 : diag::err_redefinition_different_kind)
12665 << Prev.getLookupName();
12681 if (
UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
12682 DTypename = UD->hasTypename();
12683 DQual = UD->getQualifier();
12685 = dyn_cast<UnresolvedUsingValueDecl>(D)) {
12687 DQual = UD->getQualifier();
12689 = dyn_cast<UnresolvedUsingTypenameDecl>(D)) {
12691 DQual = UD->getQualifier();
12696 if (HasTypenameKeyword != DTypename)
continue;
12704 Diag(NameLoc, diag::err_using_decl_redeclaration) << SS.
getRange();
12725 assert(
bool(NamedContext) == (R || UD) && !(R && UD) &&
12726 "resolvable context must have exactly one set of decls");
12730 bool Cxx20Enumerator =
false;
12731 if (NamedContext) {
12740 if (
auto *ED = dyn_cast<EnumDecl>(NamedContext)) {
12744 if (EC && R && ED->isScoped())
12747 ? diag::warn_cxx17_compat_using_decl_scoped_enumerator
12748 : diag::ext_using_decl_scoped_enumerator)
12752 NamedContext = ED->getDeclContext();
12772 ? diag::warn_cxx17_compat_using_decl_class_member_enumerator
12773 : diag::err_using_decl_can_not_refer_to_class_member)
12776 if (Cxx20Enumerator)
12779 auto *RD = NamedContext
12791 Diag(SS.
getBeginLoc(), diag::note_using_decl_class_member_workaround)
12799 Diag(InsertLoc, diag::note_using_decl_class_member_workaround)
12815 Diag(UsingLoc, diag::note_using_decl_class_member_workaround)
12830 Diag(UsingLoc, diag::note_using_decl_class_member_workaround)
12840 if (!NamedContext) {
12856 ? diag::warn_cxx17_compat_using_decl_non_member_enumerator
12857 : diag::err_using_decl_nested_name_specifier_is_not_class)
12860 if (Cxx20Enumerator)
12877 cast<CXXRecordDecl>(NamedContext))) {
12879 if (Cxx20Enumerator) {
12880 Diag(NameLoc, diag::warn_cxx17_compat_using_decl_non_member_enumerator)
12887 diag::err_using_decl_nested_name_specifier_is_current_class)
12892 if (!cast<CXXRecordDecl>(NamedContext)->isInvalidDecl()) {
12894 diag::err_using_decl_nested_name_specifier_is_not_base_class)
12919 Bases.insert(
Base);
12924 if (!cast<CXXRecordDecl>(
CurContext)->forallBases(Collect))
12930 return !Bases.count(
Base);
12935 if (Bases.count(cast<CXXRecordDecl>(NamedContext)) ||
12936 !cast<CXXRecordDecl>(NamedContext)->forallBases(IsNotBase))
12940 diag::err_using_decl_nested_name_specifier_is_not_base_class)
12954 while (S->isTemplateParamScope())
12955 S = S->getParent();
12957 "got alias-declaration outside of declaration scope");
12959 if (
Type.isInvalid())
12962 bool Invalid =
false;
12978 TemplateParamLists.size()
12985 Previous.getFoundDecl()->isTemplateParameter()) {
12991 "name in alias declaration must be an identifier");
12993 Name.StartLocation,
12994 Name.Identifier, TInfo);
13007 bool Redeclaration =
false;
13010 if (TemplateParamLists.size()) {
13014 if (TemplateParamLists.size() != 1) {
13015 Diag(UsingLoc, diag::err_alias_template_extra_headers)
13016 <<
SourceRange(TemplateParamLists[1]->getTemplateLoc(),
13017 TemplateParamLists[TemplateParamLists.size()-1]->getRAngleLoc());
13029 Redeclaration =
true;
13032 if (!OldDecl && !Invalid) {
13033 Diag(UsingLoc, diag::err_redefinition_different_kind)
13034 << Name.Identifier;
13048 OldTemplateParams =
13076 Name.Identifier, TemplateParams,
13084 else if (OldDecl) {
13091 if (
auto *TD = dyn_cast_or_null<TagDecl>(DeclFromDeclSpec)) {
13119 Diag(IdentLoc, diag::err_expected_namespace_name) << SS.
getRange();
13151 Diag(AliasLoc, diag::err_redefinition_different_namespace_alias)
13153 Diag(AD->getLocation(), diag::note_previous_namespace_alias)
13154 << AD->getNamespace();
13159 ? diag::err_redefinition
13160 : diag::err_redefinition_different_kind;
13161 Diag(AliasLoc, DiagID) << Alias;
13182 struct SpecialMemberExceptionSpecInfo
13183 : SpecialMemberVisitor<SpecialMemberExceptionSpecInfo> {
13191 : SpecialMemberVisitor(S, MD, CSM, ICI), Loc(Loc), ExceptSpec(S) {}
13196 void visitClassSubobject(
CXXRecordDecl *Class, Subobject Subobj,
13199 void visitSubobjectCall(Subobject Subobj,
13209 auto *BaseClass = cast<CXXRecordDecl>(RT->getDecl());
13211 if (
auto *BaseCtor = SMOR.
getMethod()) {
13212 visitSubobjectCall(
Base, BaseCtor);
13216 visitClassSubobject(BaseClass,
Base, 0);
13220 bool SpecialMemberExceptionSpecInfo::visitField(
FieldDecl *FD) {
13231 ExceptSpec.CalledExpr(E);
13234 visitClassSubobject(cast<CXXRecordDecl>(RT->getDecl()), FD,
13240 void SpecialMemberExceptionSpecInfo::visitClassSubobject(
CXXRecordDecl *Class,
13244 bool IsMutable =
Field &&
Field->isMutable();
13245 visitSubobjectCall(Subobj, lookupIn(Class, Quals, IsMutable));
13248 void SpecialMemberExceptionSpecInfo::visitSubobjectCall(
13253 ExceptSpec.CalledDecl(getSubobjectLoc(Subobj), MD);
13262 ExplicitSpec.
setKind(Result.getBoolValue()
13282 ComputingExceptionSpec CES(S, MD, Loc);
13289 SpecialMemberExceptionSpecInfo Info(S, MD, CSM, ICI, MD->
getLocation());
13291 return Info.ExceptSpec;
13298 diag::err_exception_spec_incomplete_type))
13299 return Info.ExceptSpec;
13316 Info.visit(Info.IsConstructor ? Info.VisitPotentiallyConstructedBases
13317 : Info.VisitAllBases);
13319 return Info.ExceptSpec;
13324 struct DeclaringSpecialMember {
13328 bool WasAlreadyBeingDeclared;
13331 : S(S), D(RD, CSM), SavedContext(S, RD) {
13333 if (WasAlreadyBeingDeclared)
13354 ~DeclaringSpecialMember() {
13355 if (!WasAlreadyBeingDeclared) {
13362 bool isAlreadyBeingDeclared()
const {
13363 return WasAlreadyBeingDeclared;
13383 void Sema::setupImplicitSpecialMemberType(
CXXMethodDecl *SpecialMem,
13401 cast<CXXRecordDecl>(SpecialMem->
getParent())->isLambda()) {
13417 "Should not build implicit default constructor!");
13420 if (DSM.isAlreadyBeingDeclared())
13451 setupImplicitSpecialMemberType(DefaultCon,
Context.
VoidTy, None);
13468 ClassDecl->
addDecl(DefaultCon);
13475 assert((Constructor->isDefaulted() && Constructor->isDefaultConstructor() &&
13476 !Constructor->doesThisDeclarationHaveABody() &&
13477 !Constructor->isDeleted()) &&
13478 "DefineImplicitDefaultConstructor - call it for implicit default ctor");
13479 if (Constructor->willHaveBody() || Constructor->isInvalidDecl())
13483 assert(ClassDecl &&
"DefineImplicitDefaultConstructor - invalid constructor");
13494 Scope.addContextNote(CurrentLocation);
13497 Constructor->setInvalidDecl();
13502 ? Constructor->getEndLoc()
13503 : Constructor->getLocation();
13505 Constructor->markUsed(
Context);
13508 L->CompletedImplicitDefinition(Constructor);
13511 DiagnoseUninitializedFields(*
this, Constructor);
13537 ->getInheritedConstructor()
13540 return cast<CXXConstructorDecl>(Ctor);
13555 false, BaseCtor, &ICI);
13572 EPI.ExceptionSpec.SourceDecl = DerivedCtor;
13578 for (
unsigned I = 0, N = FPT->
getNumParams(); I != N; ++I) {
13582 Context, DerivedCtor, UsingLoc, UsingLoc,
nullptr,
13589 ParamDecls.push_back(PD);
13594 assert(!BaseCtor->
isDeleted() &&
"should not use deleted constructor");
13597 Derived->
addDecl(DerivedCtor);
13602 return DerivedCtor;
13615 assert(Constructor->getInheritedConstructor() &&
13616 !Constructor->doesThisDeclarationHaveABody() &&
13617 !Constructor->isDeleted());
13618 if (Constructor->willHaveBody() || Constructor->isInvalidDecl())
13632 Scope.addContextNote(CurrentLocation);
13635 Constructor->getInheritedConstructor().getShadowDecl();
13637 Constructor->getInheritedConstructor().getConstructor();
13651 for (
bool VBase : {
false,
true}) {
13653 if (B.isVirtual() != VBase)
13656 auto *BaseRD = B.getType()->getAsCXXRecordDecl();
13661 if (!BaseCtor.first)
13666 InitLoc, B.getType(), BaseCtor.first, VBase, BaseCtor.second);
13670 Context, TInfo, VBase, InitLoc, Init.get(), InitLoc,
13679 Constructor->setInvalidDecl();
13684 Constructor->markUsed(
Context);
13687 L->CompletedImplicitDefinition(Constructor);
13690 DiagnoseUninitializedFields(*
this, Constructor);
13700 DeclaringSpecialMember DSM(*
this, ClassDecl,
CXXDestructor);
13701 if (DSM.isAlreadyBeingDeclared())
13723 Destructor->setDefaulted();
13732 setupImplicitSpecialMemberType(Destructor,
Context.
VoidTy, None);
13737 Destructor->setTrivialForCall(ClassDecl->
hasAttr<TrivialABIAttr>() ||
13756 ClassDecl->
addDecl(Destructor);
13763 assert((Destructor->isDefaulted() &&
13764 !Destructor->doesThisDeclarationHaveABody() &&
13765 !Destructor->isDeleted()) &&
13766 "DefineImplicitDestructor - call it for implicit default dtor");
13767 if (Destructor->willHaveBody() || Destructor->isInvalidDecl())
13771 assert(ClassDecl &&
"DefineImplicitDestructor - invalid destructor");
13782 Scope.addContextNote(CurrentLocation);
13785 Destructor->getParent());
13788 Destructor->setInvalidDecl();
13793 ? Destructor->getEndLoc()
13794 : Destructor->getLocation();
13796 Destructor->markUsed(
Context);
13799 L->CompletedImplicitDefinition(Destructor);
13805 if (Destructor->isInvalidDecl())
13810 "implicit complete dtors unneeded outside MS ABI");
13812 "complete dtor only exists for classes with vbases");
13817 Scope.addContextNote(CurrentLocation);
13848 if (M->getParent()->getTemplateSpecializationKind() !=
13868 "adjusting dtor exception specs was introduced in c++11");
13870 if (Destructor->isDependentContext())
13878 if (DtorType->hasExceptionSpec())
13900 class ExprBuilder {
13901 ExprBuilder(
const ExprBuilder&) =
delete;
13902 ExprBuilder &operator=(
const ExprBuilder&) =
delete;
13905 static Expr *assertNotNull(
Expr *E) {
13906 assert(E &&
"Expression construction must not fail.");
13912 virtual ~ExprBuilder() {}
13917 class RefBuilder:
public ExprBuilder {
13927 : Var(Var), VarType(VarType) {}
13930 class ThisBuilder:
public ExprBuilder {
13937 class CastBuilder:
public ExprBuilder {
13938 const ExprBuilder &Builder;
13946 CK_UncheckedDerivedToBase,
Kind,
13955 class DerefBuilder:
public ExprBuilder {
13956 const ExprBuilder &Builder;
13960 return assertNotNull(
13964 DerefBuilder(
const ExprBuilder &Builder) : Builder(Builder) {}
13967 class MemberBuilder:
public ExprBuilder {
13968 const ExprBuilder &Builder;
13978 nullptr, MemberLookup,
nullptr,
nullptr).get());
13981 MemberBuilder(
const ExprBuilder &Builder,
QualType Type,
bool IsArrow,
13983 : Builder(Builder),
Type(
Type), IsArrow(IsArrow),
13984 MemberLookup(MemberLookup) {}
13987 class MoveCastBuilder:
public ExprBuilder {
13988 const ExprBuilder &Builder;
13992 return assertNotNull(
CastForMoving(S, Builder.build(S, Loc)));
13995 MoveCastBuilder(
const ExprBuilder &Builder) : Builder(Builder) {}
13998 class LvalueConvBuilder:
public ExprBuilder {
13999 const ExprBuilder &Builder;
14003 return assertNotNull(
14007 LvalueConvBuilder(
const ExprBuilder &Builder) : Builder(Builder) {}
14010 class SubscriptBuilder:
public ExprBuilder {
14011 const ExprBuilder &
Base;
14012 const ExprBuilder &Index;
14017 Base.build(S, Loc), Loc, Index.build(S, Loc), Loc).
get());
14020 SubscriptBuilder(
const ExprBuilder &
Base,
const ExprBuilder &Index)
14032 const ExprBuilder &ToB,
const ExprBuilder &FromB) {
14041 Expr *From = FromB.build(S, Loc);
14045 Expr *To = ToB.build(S, Loc);
14051 bool NeedsCollectableMemCpy =
14056 StringRef MemCpyName = NeedsCollectableMemCpy ?
14057 "__builtin_objc_memmove_collectable" :
14058 "__builtin_memcpy";
14071 assert(MemCpyRef.
isUsable() &&
"Builtin reference cannot fail");
14073 Expr *CallArgs[] = {
14077 Loc, CallArgs, Loc);
14079 assert(!Call.isInvalid() &&
"Call to __builtin_memcpy cannot fail!");
14080 return Call.getAs<
Stmt>();
14112 const ExprBuilder &To,
const ExprBuilder &From,
14113 bool CopyingBaseSubobject,
bool Copying,
14114 unsigned Depth = 0) {
14130 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(RecordTy->getDecl());
14165 if (CopyingBaseSubobject) {
14196 Expr *FromInst = From.build(S, Loc);
14199 Loc, FromInst, Loc);
14200 if (Call.isInvalid())
14219 Loc, BO_Assign, To.build(S, Loc), From.build(S, Loc));
14239 llvm::raw_svector_ostream OS(Str);
14240 OS <<
"__i" <<
Depth;
14244 IterationVarName, SizeType,
14253 RefBuilder IterationVarRef(IterationVar, SizeType);
14254 LvalueConvBuilder IterationVarRefRVal(IterationVarRef);
14260 SubscriptBuilder FromIndexCopy(From, IterationVarRefRVal);
14261 MoveCastBuilder FromIndexMove(FromIndexCopy);
14262 const ExprBuilder *FromIndex;
14264 FromIndex = &FromIndexCopy;
14266 FromIndex = &FromIndexMove;
14268 SubscriptBuilder ToIndex(To, IterationVarRefRVal);
14273 ToIndex, *FromIndex, CopyingBaseSubobject,
14274 Copying,
Depth + 1);
14276 if (Copy.isInvalid() || !Copy.get())
14283 S.
Context, IterationVarRefRVal.build(S, Loc),
14297 Loc, Loc, InitStmt,
14304 const ExprBuilder &To,
const ExprBuilder &From,
14305 bool CopyingBaseSubobject,
bool Copying) {
14312 CopyingBaseSubobject,
14317 if (!Result.isInvalid() && !Result.get())
14331 if (DSM.isAlreadyBeingDeclared())
14372 setupImplicitSpecialMemberType(CopyAssignment, RetType, ArgType);
14376 ClassLoc, ClassLoc,
14400 ClassDecl->
addDecl(CopyAssignment);
14402 return CopyAssignment;
14418 }
else if (!isa<CXXConstructorDecl>(CopyOp) &&
14422 for (
auto *I : RD->
ctors()) {
14423 if (I->isCopyConstructor()) {
14424 UserDeclaredOperation = I;
14428 assert(UserDeclaredOperation);
14429 }
else if (isa<CXXConstructorDecl>(CopyOp) &&
14433 for (
auto *I : RD->
methods()) {
14434 if (I->isCopyAssignmentOperator()) {
14435 UserDeclaredOperation = I;
14439 assert(UserDeclaredOperation);
14442 if (UserDeclaredOperation) {
14443 bool UDOIsUserProvided = UserDeclaredOperation->
isUserProvided();
14444 bool UDOIsDestructor = isa<CXXDestructorDecl>(UserDeclaredOperation);
14445 bool IsCopyAssignment = !isa<CXXConstructorDecl>(CopyOp);
14447 (UDOIsUserProvided && UDOIsDestructor)
14448 ? diag::warn_deprecated_copy_with_user_provided_dtor
14449 : (UDOIsUserProvided && !UDOIsDestructor)
14450 ? diag::warn_deprecated_copy_with_user_provided_copy
14451 : (!UDOIsUserProvided && UDOIsDestructor)
14452 ? diag::warn_deprecated_copy_with_dtor
14453 : diag::warn_deprecated_copy;
14455 << RD << IsCopyAssignment;
14466 "DefineImplicitCopyAssignment called for wrong function");
14484 Scope.addContextNote(CurrentLocation);
14520 RefBuilder OtherRef(Other, OtherRefType);
14526 bool Invalid =
false;
14527 for (
auto &
Base : ClassDecl->
bases()) {
14530 QualType BaseType =
Base.getType().getUnqualifiedType();
14537 BasePath.push_back(&
Base);
14545 DerefBuilder DerefThis(
This);
14546 CastBuilder To(DerefThis,
14562 Statements.push_back(Copy.
getAs<
Expr>());
14566 for (
auto *Field : ClassDecl->
fields()) {
14569 if (Field->isUnnamedBitfield() || Field->getParent()->isUnion())
14572 if (Field->isInvalidDecl()) {
14578 if (Field->getType()->isReferenceType()) {
14579 Diag(ClassDecl->
getLocation(), diag::err_uninitialized_member_for_assign)
14581 Diag(Field->getLocation(), diag::note_declared_at);
14589 Diag(ClassDecl->
getLocation(), diag::err_uninitialized_member_for_assign)
14591 Diag(Field->getLocation(), diag::note_declared_at);
14597 if (Field->isZeroLengthBitField(
Context))
14600 QualType FieldType = Field->getType().getNonReferenceType();
14603 "Incomplete array type is not valid");
14609 LookupResult MemberLookup(*
this, Field->getDeclName(), Loc,
14614 MemberBuilder From(OtherRef, OtherRefType,
false, MemberLookup);
14629 Statements.push_back(Copy.
getAs<
Stmt>());
14640 Statements.push_back(Return.
getAs<
Stmt>());
14653 assert(!Body.
isInvalid() &&
"Compound statement creation cannot fail");
14659 L->CompletedImplicitDefinition(CopyAssignOperator);
14667 if (DSM.isAlreadyBeingDeclared())
14707 setupImplicitSpecialMemberType(MoveAssignment, RetType, ArgType);
14711 ClassLoc, ClassLoc,
14735 ClassDecl->
addDecl(MoveAssignment);
14737 return MoveAssignment;
14745 assert(!Class->isDependentContext() &&
"should not define dependent move");
14751 if (Class->getNumVBases() == 0 || Class->hasTrivialMoveAssignment() ||
14752 Class->getNumBases() < 2)
14756 typedef llvm::DenseMap<CXXRecordDecl*, CXXBaseSpecifier*> VBaseMap;
14759 for (
auto &BI : Class->bases()) {
14760 Worklist.push_back(&BI);
14761 while (!Worklist.empty()) {
14767 if (!
Base->hasNonTrivialMoveAssignment())
14792 VBases.insert(std::make_pair(
Base->getCanonicalDecl(), &BI))
14794 if (Existing && Existing != &BI) {
14795 S.
Diag(CurrentLocation, diag::warn_vbase_moved_multiple_times)
14798 << (
Base->getCanonicalDecl() ==
14801 S.
Diag(BI.getBeginLoc(), diag::note_vbase_moved_here)
14802 << (
Base->getCanonicalDecl() ==
14803 BI.getType()->getAsCXXRecordDecl()->getCanonicalDecl())
14807 Existing =
nullptr;
14817 llvm::append_range(Worklist, llvm::make_pointer_range(
Base->bases()));
14830 "DefineImplicitMoveAssignment called for wrong function");
14860 Scope.addContextNote(CurrentLocation);
14876 RefBuilder OtherRef(Other, OtherRefType);
14878 MoveCastBuilder MoveOther(OtherRef);
14884 bool Invalid =
false;
14885 for (
auto &
Base : ClassDecl->
bases()) {
14896 QualType BaseType =
Base.getType().getUnqualifiedType();
14903 BasePath.push_back(&
Base);
14907 CastBuilder From(OtherRef, BaseType,
VK_XValue, BasePath);
14910 DerefBuilder DerefThis(
This);
14913 CastBuilder To(DerefThis,
14923 if (
Move.isInvalid()) {
14929 Statements.push_back(
Move.getAs<
Expr>());
14933 for (
auto *Field : ClassDecl->
fields()) {
14936 if (Field->isUnnamedBitfield() || Field->getParent()->isUnion())
14939 if (Field->isInvalidDecl()) {
14945 if (Field->getType()->isReferenceType()) {
14946 Diag(ClassDecl->
getLocation(), diag::err_uninitialized_member_for_assign)
14948 Diag(Field->getLocation(), diag::note_declared_at);
14956 Diag(ClassDecl->
getLocation(), diag::err_uninitialized_member_for_assign)
14958 Diag(Field->getLocation(), diag::note_declared_at);
14964 if (Field->isZeroLengthBitField(
Context))
14967 QualType FieldType = Field->getType().getNonReferenceType();
14970 "Incomplete array type is not valid");
14975 LookupResult MemberLookup(*
this, Field->getDeclName(), Loc,
14979 MemberBuilder From(MoveOther, OtherRefType,
14980 false, MemberLookup);
14982 true, MemberLookup);
14984 assert(!From.build(*
this, Loc)->isLValue() &&
14985 "Member reference with rvalue base must be rvalue except for reference "
14986 "members, which aren't allowed for move assignment.");
14993 if (
Move.isInvalid()) {
14999 Statements.push_back(
Move.getAs<
Stmt>());
15011 Statements.push_back(Return.
getAs<
Stmt>());
15024 assert(!Body.
isInvalid() &&
"Compound statement creation cannot fail");
15030 L->CompletedImplicitDefinition(MoveAssignOperator);
15042 if (DSM.isAlreadyBeingDeclared())
15086 setupImplicitSpecialMemberType(CopyConstructor,
Context.
VoidTy, ArgType);
15108 ClassDecl->
hasAttr<TrivialABIAttr>() ||
15127 ClassDecl->
addDecl(CopyConstructor);
15129 return CopyConstructor;
15138 "DefineImplicitCopyConstructor - call it for implicit copy ctor");
15143 assert(ClassDecl &&
"DefineImplicitCopyConstructor - invalid constructor");
15154 Scope.addContextNote(CurrentLocation);
15176 L->CompletedImplicitDefinition(CopyConstructor);
15185 if (DSM.isAlreadyBeingDeclared())
15226 setupImplicitSpecialMemberType(MoveConstructor,
Context.
VoidTy, ArgType);
15230 ClassLoc, ClassLoc,
15242 ClassDecl->
hasAttr<TrivialABIAttr>() ||
15261 ClassDecl->
addDecl(MoveConstructor);
15263 return MoveConstructor;
15272 "DefineImplicitMoveConstructor - call it for implicit move ctor");
15277 assert(ClassDecl &&
"DefineImplicitMoveConstructor - invalid constructor");
15288 Scope.addContextNote(CurrentLocation);
15298 Loc, Loc, None,
false).getAs<Stmt>());
15303 L->CompletedImplicitDefinition(MoveConstructor);
15358 assert(FunctionRef &&
"Can't refer to __invoke function?");
15366 L->CompletedImplicitDefinition(Conv);
15367 L->CompletedImplicitDefinition(Invoker);
15399 Diag(CurrentLocation, diag::note_lambda_to_block_conv);
15408 Diag(CurrentLocation, diag::note_lambda_to_block_conv);
15414 Stmt *ReturnS = Return.
get();
15421 L->CompletedImplicitDefinition(Conv);
15428 switch (Args.size()) {
15433 if (!Args[1]->isDefaultArgument())
15438 return !Args[0]->isDefaultArgument();
15449 bool HadMultipleCandidates,
15450 bool IsListInitialization,
15451 bool IsStdInitListInitialization,
15452 bool RequiresZeroInit,
15453 unsigned ConstructKind,
15455 bool Elidable =
false;
15474 Expr *SubExpr = ExprArgs[0];
15484 FoundDecl, Constructor,
15485 Elidable, ExprArgs, HadMultipleCandidates,
15486 IsListInitialization,
15487 IsStdInitListInitialization, RequiresZeroInit,
15488 ConstructKind, ParenRange);
15497 bool HadMultipleCandidates,
15498 bool IsListInitialization,
15499 bool IsStdInitListInitialization,
15500 bool RequiresZeroInit,
15501 unsigned ConstructKind,
15503 if (
auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(FoundDecl)) {
15510 ConstructLoc, DeclInitType, Constructor, Elidable, ExprArgs,
15511 HadMultipleCandidates, IsListInitialization, IsStdInitListInitialization,
15512 RequiresZeroInit, ConstructKind, ParenRange);
15522 bool HadMultipleCandidates,
15523 bool IsListInitialization,
15524 bool IsStdInitListInitialization,
15525 bool RequiresZeroInit,
15526 unsigned ConstructKind,
15529 Constructor->getParent(),
15531 "given constructor for wrong type");
15541 Context, DeclInitType, ConstructLoc, Constructor, Elidable, ExprArgs,
15542 HadMultipleCandidates, IsListInitialization,
15543 IsStdInitListInitialization, RequiresZeroInit,
15550 assert(Field->hasInClassInitializer());
15553 if (Field->getInClassInitializer())
15557 if (Field->isInvalidDecl())
15562 CXXRecordDecl *ParentRD = cast<CXXRecordDecl>(Field->getParent());
15567 ClassPattern->
lookup(Field->getDeclName());
15570 for (
auto L : Lookup) {
15571 if (isa<FieldDecl>(L)) {
15572 Pattern = cast<FieldDecl>(L);
15576 assert(Pattern &&
"We must have set the Pattern!");
15582 Field->setInvalidDecl();
15603 Diag(Loc, diag::err_default_member_initializer_not_yet_parsed)
15604 << OutermostClass << Field;
15605 Diag(Field->getEndLoc(),
15606 diag::note_default_member_initializer_not_yet_parsed);
15609 Field->setInvalidDecl();
15636 PDiag(diag::err_access_dtor_var)
15641 if (Destructor->isTrivial())
return;
15645 if (Destructor->isConstexpr()) {
15646 bool HasConstantInit =
false;
15653 diag::err_constexpr_var_requires_const_destruction) << VD;
15654 for (
unsigned I = 0, N = Notes.size(); I != N; ++I)
15655 Diag(Notes[I].first, Notes[I].second);
15679 bool AllowExplicit,
15680 bool IsListInitialization) {
15682 unsigned NumArgs = ArgsPtr.size();
15683 Expr **Args = ArgsPtr.data();
15689 if (NumArgs < NumParams)
15690 ConvertedArgs.reserve(NumParams);
15692 ConvertedArgs.reserve(NumArgs);
15699 llvm::makeArrayRef(Args, NumArgs),
15701 CallType, AllowExplicit,
15702 IsListInitialization);
15703 ConvertedArgs.append(AllArgs.begin(), AllArgs.end());
15707 CheckConstructorCall(Constructor, DeclInitType,
15708 llvm::makeArrayRef(AllArgs.data(), AllArgs.size()),
15718 if (isa<NamespaceDecl>(DC)) {
15720 diag::err_operator_new_delete_declared_in_namespace)
15724 if (isa<TranslationUnitDecl>(DC) &&
15727 diag::err_operator_new_delete_declared_static)
15739 return Ctx.getPointerType(Ctx.getCanonicalType(Ctx.getQualifiedType(
15747 unsigned DependentParamTypeDiag,
15748 unsigned InvalidParamTypeDiag) {
15766 return SemaRef.
Diag(
15769 ? diag::err_operator_new_delete_dependent_result_type
15770 : diag::err_operator_new_delete_invalid_result_type)
15777 diag::err_operator_new_delete_template_too_few_parameters)
15783 diag::err_operator_new_delete_too_few_parameters)
15790 if (
const auto *PtrTy =
15795 ExpectedFirstParamType =
15801 ExpectedFirstParamType) {
15806 ? DependentParamTypeDiag
15807 : InvalidParamTypeDiag)
15808 << FnDecl->
getDeclName() << ExpectedFirstParamType;
15831 diag::err_operator_new_dependent_param_type,
15832 diag::err_operator_new_param_type))
15839 diag::err_operator_new_default_arg)
15854 auto *MD = dyn_cast<CXXMethodDecl>(FnDecl);
15869 SemaRef, FnDecl, SemaRef.
Context.
VoidTy, ExpectedFirstParamType,
15870 diag::err_operator_delete_dependent_param_type,
15871 diag::err_operator_delete_param_type))
15880 diag::err_destroying_operator_delete_not_usual);
15892 "Expected an overloaded operator declaration");
15902 if (Op == OO_Delete || Op == OO_Array_Delete)
15905 if (Op == OO_New || Op == OO_Array_New)
15913 if (
CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(FnDecl)) {
15914 if (MethodDecl->isStatic())
15916 diag::err_operator_overload_static) << FnDecl->
getDeclName();
15918 bool ClassOrEnumParam =
false;
15920 QualType ParamType = Param->getType().getNonReferenceType();
15923 ClassOrEnumParam =
true;
15928 if (!ClassOrEnumParam)
15930 diag::err_operator_overload_needs_class_or_enum)
15940 if (Op != OO_Call) {
15943 if (Param->hasDefaultArg()) {
15944 FirstDefaultedParam = Param;
15948 if (FirstDefaultedParam) {
15949 if (Op == OO_Subscript) {
15951 ? diag::ext_subscript_overload
15952 : diag::error_subscript_overload)
15957 diag::err_operator_overload_default_arg)
15965 {
false,
false,
false }
15966 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
15967 , { Unary, Binary, MemberOnly }
15968 #include "clang/Basic/OperatorKinds.def"
15971 bool CanBeUnaryOperator = OperatorUses[Op][0];
15972 bool CanBeBinaryOperator = OperatorUses[Op][1];
15973 bool MustBeMemberOperator = OperatorUses[Op][2];
15980 + (isa<CXXMethodDecl>(FnDecl)? 1 : 0);
15981 if (Op != OO_Call && Op != OO_Subscript &&
15982 ((NumParams == 1 && !CanBeUnaryOperator) ||
15983 (NumParams == 2 && !CanBeBinaryOperator) || (NumParams < 1) ||
15984 (NumParams > 2))) {
15986 unsigned ErrorKind;
15987 if (CanBeUnaryOperator && CanBeBinaryOperator) {
15989 }
else if (CanBeUnaryOperator) {
15992 assert(CanBeBinaryOperator &&
15993 "All non-call overloaded operators are unary or binary!");
15996 return Diag(FnDecl->
getLocation(), diag::err_operator_overload_must_be)
15997 << FnDecl->
getDeclName() << NumParams << ErrorKind;
16000 if (Op == OO_Subscript && NumParams != 2) {
16002 ? diag::ext_subscript_overload
16003 : diag::error_subscript_overload)
16004 << FnDecl->
getDeclName() << (NumParams == 1 ? 0 : 2);
16009 if (Op != OO_Call &&
16011 return Diag(FnDecl->
getLocation(), diag::err_operator_overload_variadic)
16016 if (MustBeMemberOperator && !isa<CXXMethodDecl>(FnDecl)) {
16018 diag::err_operator_overload_must_be_member)
16032 if ((Op == OO_PlusPlus || Op == OO_MinusMinus) && NumParams == 2) {
16039 diag::err_operator_overload_post_incdec_must_be_int)
16040 << LastParam->
getType() << (Op == OO_MinusMinus);
16052 if (TemplateParams->
size() == 1) {
16054 dyn_cast<NonTypeTemplateParmDecl>(TemplateParams->
getParam(0));
16068 if (SemaRef.
getLangOpts().CPlusPlus20 && PmDecl &&
16073 }
else if (TemplateParams->
size() == 2) {
16075 dyn_cast<TemplateTypeParmDecl>(TemplateParams->
getParam(0));
16077 dyn_cast<NonTypeTemplateParmDecl>(TemplateParams->
getParam(1));
16089 diag::ext_string_literal_operator_template);
16096 diag::err_literal_operator_template)
16105 if (isa<CXXMethodDecl>(FnDecl)) {
16106 Diag(FnDecl->
getLocation(), diag::err_literal_operator_outside_namespace)
16115 Diag(LSD->getExternLoc(), diag::note_extern_c_begins_here);
16134 diag::err_literal_operator_template_with_params);
16163 diag::err_literal_operator_param)
16180 diag::err_literal_operator_invalid_param)
16190 QualType FirstParamType = (*Param)->getType().getUnqualifiedType();
16197 Diag((*Param)->getSourceRange().getBegin(),
16198 diag::err_literal_operator_param)
16199 << FirstParamType <<
"'const char *'" << (*Param)->getSourceRange();
16206 Diag((*Param)->getSourceRange().getBegin(),
16207 diag::err_literal_operator_param)
16208 << FirstParamType <<
"'const char *'" << (*Param)->getSourceRange();
16221 Diag((*Param)->getSourceRange().getBegin(),
16222 diag::err_literal_operator_param)
16223 << FirstParamType <<
"'const char *'" << (*Param)->getSourceRange();
16231 QualType SecondParamType = (*Param)->getType().getUnqualifiedType();
16233 Diag((*Param)->getSourceRange().getBegin(),
16234 diag::err_literal_operator_param)
16236 << (*Param)->getSourceRange();
16240 Diag(FnDecl->
getLocation(), diag::err_literal_operator_bad_param_count);
16249 if (Param->hasDefaultArg()) {
16250 Diag(Param->getDefaultArgRange().getBegin(),
16251 diag::err_literal_operator_default_argument)
16252 << Param->getDefaultArgRange();
16257 StringRef LiteralName
16259 if (LiteralName[0] !=
'_' &&
16282 Diag(LangStr->
getExprLoc(), diag::err_language_linkage_spec_not_ascii)
16291 else if (Lang ==
"C++")
16294 Diag(LangStr->
getExprLoc(), diag::err_language_linkage_spec_unknown)
16314 if (
getLangOpts().CPlusPlusModules && isCurrentModulePurview()) {
16316 PushGlobalModuleFragment(ExternLoc,
true);
16341 if (
getLangOpts().CPlusPlusModules && getCurrentModule() &&
16342 getCurrentModule()->isGlobalModule() && getCurrentModule()->
Parent)
16343 PopGlobalModuleFragment();
16346 return LinkageSpec;
16369 bool Invalid =
false;
16383 Diag(Loc, diag::err_catch_rvalue_ref);
16388 Diag(Loc, diag::err_catch_variably_modified) << ExDeclType;
16394 unsigned DK = diag::err_catch_incomplete;
16398 DK = diag::err_catch_incomplete_ptr;
16401 BaseType = Ref->getPointeeType();
16403 DK = diag::err_catch_incomplete_ref;
16405 if (!Invalid && (Mode == 0 || !BaseType->
isVoidType()) &&
16410 Diag(Loc, diag::err_catch_sizeless) << (Mode == 2 ? 1 : 0) << BaseType;
16416 diag::err_abstract_type_in_decl,
16428 Diag(Loc, diag::err_objc_object_catch);
16433 Diag(Loc, diag::warn_objc_pointer_cxx_catch_fragile);
16467 Expr *opaqueValue =
16515 assert(!S->isDeclScope(PrevDecl));
16519 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
16521 }
else if (PrevDecl->isTemplateParameter())
16549 Expr *AssertMessageExpr,
16552 AssertMessageExpr ? cast<StringLiteral>(AssertMessageExpr) :
nullptr;
16558 AssertMessage, RParenLoc,
false);
16566 assert(AssertExpr !=
nullptr &&
"Expected non-null condition");
16582 AssertExpr = FullAssertExpr.
get();
16587 diag::err_static_assert_expression_is_not_constant)
16591 if (!Failed && !Cond) {
16593 llvm::raw_svector_ostream Msg(MsgBuffer);
16597 Expr *InnerCond =
nullptr;
16599 std::tie(InnerCond, InnerCondDescription) =
16601 if (InnerCond && isa<ConceptSpecializationExpr>(InnerCond)) {
16604 Diag(StaticAssertLoc, diag::err_static_assert_failed)
16609 }
else if (InnerCond && !isa<CXXBoolLiteralExpr>(InnerCond)
16610 && !isa<IntegerLiteral>(InnerCond)) {
16611 Diag(StaticAssertLoc, diag::err_static_assert_requirement_failed)
16612 << InnerCondDescription << !AssertMessage
16615 Diag(StaticAssertLoc, diag::err_static_assert_failed)
16627 AssertExpr = FullAssertExpr.
get();
16631 AssertExpr, AssertMessage, RParenLoc,
16644 assert(TSInfo &&
"NULL TypeSourceInfo for friend type declaration");
16670 diag::warn_cxx98_compat_unelaborated_friend_type :
16671 diag::ext_unelaborated_friend_type)
16679 diag::warn_cxx98_compat_nonclass_type_friend :
16680 diag::ext_nonclass_type_friend)
16687 diag::warn_cxx98_compat_enum_friend :
16688 diag::ext_enum_friend)
16700 Diag(FriendLoc, diag::err_friend_not_first_in_declaration) << T;
16721 bool IsMemberSpecialization =
false;
16722 bool Invalid =
false;
16726 TagLoc, NameLoc, SS,
nullptr, TempParamLists,
true,
16727 IsMemberSpecialization, Invalid)) {
16728 if (TemplateParams->size() > 0) {
16736 FriendLoc, TempParamLists.size() - 1,
16737 TempParamLists.data()).
get();
16740 Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
16742 IsMemberSpecialization =
true;
16746 if (Invalid)
return nullptr;
16748 bool isAllExplicitSpecializations =
true;
16749 for (
unsigned I = TempParamLists.size(); I-- > 0; ) {
16750 if (TempParamLists[I]->size()) {
16751 isAllExplicitSpecializations =
false;
16761 if (isAllExplicitSpecializations) {
16763 bool Owned =
false;
16764 bool IsDependent =
false;
16785 if (isa<DependentNameType>(T)) {
16799 TSI, FriendLoc, TempParamLists);
16805 assert(SS.
isNotEmpty() &&
"valid templated tag with no SS and no direct?");
16812 Diag(NameLoc, diag::warn_template_qualified_friend_unsupported)
16823 TSI, FriendLoc, TempParamLists);
16904 Diag(Loc, diag::err_tagless_friend_type_template)
16921 if (!TempParams.empty())
16959 Diag(Loc, diag::err_unexpected_friend);
16994 Scope *DCScope = S;
17004 (FunctionContainingLocalClass =
17005 cast<CXXRecordDecl>(
CurContext)->isLocalClass())) {
17017 DCScope = S->getFnParent();
17027 DC =
Previous.getRepresentativeDecl()->getDeclContext();
17031 DC = FunctionContainingLocalClass;
17053 bool isTemplateId =
17078 if (isTemplateId) {
17079 if (isa<TranslationUnitDecl>(LookupDC))
break;
17093 if (!DC)
return nullptr;
17104 diag::warn_cxx98_compat_friend_is_member :
17105 diag::err_friend_is_member);
17141 assert(isa<CXXRecordDecl>(DC) &&
"friend declaration not in class?");
17168 if (DiagArg >= 0) {
17169 Diag(Loc, diag::err_introducing_special_friend) << DiagArg;
17180 DCScope = &FakeDCScope;
17183 bool AddToScope =
true;
17185 TemplateParams, AddToScope);
17186 if (!ND)
return nullptr;
17220 FD = FTD->getTemplatedDecl();
17222 FD = cast<FunctionDecl>(ND);
17233 Diag(FD->
getLocation(), diag::err_friend_decl_with_def_arg_redeclared);
17235 diag::note_previous_declaration);
17237 Diag(FD->
getLocation(), diag::err_friend_decl_with_def_arg_must_be_def);
17242 Diag(FD->
getLocation(), diag::warn_template_qualified_friend_unsupported)
17257 FunctionDecl *Fn = dyn_cast_or_null<FunctionDecl>(Dcl);
17259 Diag(DelLoc, diag::err_deleted_non_function);
17270 Prev->getPreviousDecl()) &&
17271 !Prev->isDefined()) {
17272 Diag(DelLoc, diag::err_deleted_decl_not_first);
17273 Diag(Prev->getLocation().isInvalid() ? DelLoc : Prev->getLocation(),
17274 Prev->isImplicit() ? diag::note_previous_implicit_declaration
17275 : diag::note_previous_declaration);
17298 Diag(DelLoc, diag::err_deleted_main);
17310 auto *FD = dyn_cast<FunctionDecl>(Dcl);
17312 if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(Dcl)) {
17314 Diag(DefaultLoc, diag::err_defaulted_comparison_template);
17319 Diag(DefaultLoc, diag::err_default_special_members)
17330 (!FD->isDependentContext() ||
17331 (!isa<CXXConstructorDecl>(FD) &&
17333 Diag(DefaultLoc, diag::err_default_special_members)
17343 ? diag::warn_cxx17_compat_defaulted_comparison
17344 : diag::ext_defaulted_comparison);
17347 FD->setDefaulted();
17348 FD->setExplicitlyDefaulted();
17351 if (FD->isDependentContext())
17357 FD->setWillHaveBody(
false);
17370 if (isa<CXXMethodDecl>(FD)) {
17372 if (
const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern())
17386 auto *MD = cast<CXXMethodDecl>(FD);
17396 for (
Stmt *SubStmt : S->children()) {
17399 if (isa<ReturnStmt>(SubStmt))
17400 Self.
Diag(SubStmt->getBeginLoc(),
17401 diag::err_return_in_constructor_handler);
17402 if (!isa<Expr>(SubStmt))
17408 for (
unsigned I = 0, E = TryBlock->
getNumHandlers(); I != E; ++I) {
17420 for (
unsigned I = 0, E = OldFT->
getNumParams(); I != E; ++I)
17424 !NewFT->getExtParameterInfo(I).isNoEscape()) {
17426 diag::warn_overriding_method_missing_noescape);
17428 diag::note_overridden_marked_noescape);
17433 const auto *OldCSA = Old->
getAttr<CodeSegAttr>();
17434 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
17435 if ((NewCSA || OldCSA) &&
17436 (!OldCSA || !NewCSA || NewCSA->getName() != OldCSA->getName())) {
17445 if (NewCC == OldCC)
17456 diag::err_conflicting_overriding_cc_attributes)
17482 if (NewRT->getTypeClass() == OldRT->getTypeClass()) {
17490 if (NewClassTy.
isNull()) {
17492 diag::err_different_return_type_for_overriding_virtual_function)
17508 if (!RT->isBeingDefined() &&
17510 diag::err_covariant_return_incomplete,
17527 NewClassTy, OldClassTy,
17528 diag::err_covariant_return_inaccessible_base,
17529 diag::err_covariant_return_ambiguous_derived_to_base_conv,
17545 diag::err_covariant_return_type_different_qualifications)
17557 diag::err_covariant_return_type_class_type_more_qualified)
17592 else if (
auto *M = dyn_cast<CXXMethodDecl>(D))
17601 if (
const VarDecl *Var = dyn_cast_or_null<VarDecl>(D))
17602 return Var->hasGlobalStorage();
17656 "Parser allowed 'typedef' as storage class of condition decl.");
17662 if (isa<FunctionDecl>(Dcl)) {
17672 if (!ExternalSource)
17678 for (
unsigned I = 0, N = VTables.size(); I != N; ++I) {
17679 llvm::DenseMap<CXXRecordDecl *, bool>::iterator Pos
17683 if (!Pos->second && VTables[I].DefinitionRequired)
17684 Pos->second =
true;
17688 VTablesUsed[VTables[I].Record] = VTables[I].DefinitionRequired;
17689 NewUses.push_back(
VTableUse(VTables[I].Record, VTables[I].Location));
17696 bool DefinitionRequired) {
17699 if (!Class->isDynamicClass() || Class->isDependentContext() ||
17707 if (!DefinitionRequired)
17714 Class = Class->getCanonicalDecl();
17715 std::pair<llvm::DenseMap<CXXRecordDecl *, bool>::iterator,
bool>
17716 Pos =
VTablesUsed.insert(std::make_pair(Class, DefinitionRequired));
17721 if (DefinitionRequired && !Pos.first->second) {
17722 Pos.first->second =
true;
17735 if (Class->hasUserDeclaredDestructor() && !DD->
isDefined()) {
17751 if (Class->isLocalClass())
17754 VTableUses.push_back(std::make_pair(Class, Loc));
17766 bool DefinedAnything =
false;
17767 for (
unsigned I = 0; I !=
VTableUses.size(); ++I) {
17772 Class->getTemplateSpecializationKind();
17776 bool DefineVTable =
true;
17782 if (KeyFunction && !KeyFunction->
hasBody()) {
17784 DefineVTable =
false;
17789 "Instantiations don't have key functions");
17791 }
else if (!KeyFunction) {
17796 bool IsExplicitInstantiationDeclaration =
17798 for (
auto R : Class->redecls()) {
17800 = cast<CXXRecordDecl>(R)->getTemplateSpecializationKind();
17802 IsExplicitInstantiationDeclaration =
true;
17804 IsExplicitInstantiationDeclaration =
false;
17809 if (IsExplicitInstantiationDeclaration)
17810 DefineVTable =
false;
17816 if (!DefineVTable) {
17824 DefinedAnything =
true;
17837 if (!KeyFunction || (KeyFunction->
hasBody(KeyFunctionDef) &&
17839 Diag(Class->getLocation(), diag::warn_weak_vtable) << Class;
17844 return DefinedAnything;
17849 for (
const auto *I : RD->
methods())
17850 if (I->isVirtual() && !I->isPure())
17856 bool ConstexprOnly) {
17860 for (CXXFinalOverriderMap::const_iterator I = FinalOverriders.begin(),
17861 E = FinalOverriders.end();
17864 OE = I->second.end();
17866 assert(OI->second.size() > 0 &&
"no final overrider");
17880 for (
const auto &I : RD->
bases()) {
17883 if (
Base->getNumVBases() == 0)
17900 for (
unsigned i = 0; i < ivars.size(); i++) {
17902 if (Field->isInvalidDecl())
17912 InitSeq.
Perform(*
this, InitEntity, InitKind, None);
17924 AllToInit.push_back(
Member);
17929 ->getAs<RecordType>()) {
17930 CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
17934 PDiag(diag::err_access_dtor_ivar)
17940 AllToInit.data(), AllToInit.size());
17959 (void)
Target->hasBody(FNTarget);
17961 cast_or_null<CXXConstructorDecl>(FNTarget));
17966 *TCanonical =
Target?
Target->getCanonicalDecl() :
nullptr;
17968 if (!Current.insert(Canonical).second)
17973 Target->isInvalidDecl() || Valid.count(TCanonical)) {
17974 Valid.insert(Current.begin(), Current.end());
17977 }
else if (TCanonical == Canonical || Invalid.count(TCanonical) ||
17978 Current.count(TCanonical)) {
17980 if (!Invalid.count(TCanonical)) {
17982 diag::warn_delegating_ctor_cycle)
17986 if (TCanonical != Canonical)
17987 S.
Diag(
Target->getLocation(), diag::note_it_delegates_to);
17990 while (C->getCanonicalDecl() != Canonical) {
17992 (void)C->getTargetConstructor()->hasBody(FNTarget);
17993 assert(FNTarget &&
"Ctor cycle through bodiless function");
17996 cast<CXXConstructorDecl>(FNTarget));
17997 S.
Diag(C->getLocation(), diag::note_which_delegates_to);
18001 Invalid.insert(Current.begin(), Current.end());
18012 for (DelegatingCtorDeclsType::iterator
18018 for (
auto CI = Invalid.begin(), CE = Invalid.end(); CI != CE; ++CI)
18019 (*CI)->setInvalidDecl();
18028 explicit FindCXXThisExpr(
Sema &S) : S(S) { }
18056 FindCXXThisExpr Finder(*
this);
18069 if (!Finder.TraverseStmt(E))
18086 FindCXXThisExpr Finder(*
this);
18108 if (!Finder.TraverseType(E))
18118 FindCXXThisExpr Finder(*
this);
18121 for (
const auto *A : Method->
attrs()) {
18123 Expr *Arg =
nullptr;
18125 if (
const auto *G = dyn_cast<GuardedByAttr>(A))
18127 else if (
const auto *G = dyn_cast<PtGuardedByAttr>(A))
18129 else if (
const auto *AA = dyn_cast<AcquiredAfterAttr>(A))
18130 Args = llvm::makeArrayRef(AA->args_begin(), AA->args_size());
18131 else if (
const auto *AB = dyn_cast<AcquiredBeforeAttr>(A))
18132 Args = llvm::makeArrayRef(AB->args_begin(), AB->args_size());
18133 else if (
const auto *ETLF = dyn_cast<ExclusiveTrylockFunctionAttr>(A)) {
18134 Arg = ETLF->getSuccessValue();
18135 Args = llvm::makeArrayRef(ETLF->args_begin(), ETLF->args_size());
18136 }
else if (
const auto *STLF = dyn_cast<SharedTrylockFunctionAttr>(A)) {
18137 Arg = STLF->getSuccessValue();
18138 Args = llvm::makeArrayRef(STLF->args_begin(), STLF->args_size());
18139 }
else if (
const auto *LR = dyn_cast<LockReturnedAttr>(A))
18140 Arg = LR->getArg();
18141 else if (
const auto *
LE = dyn_cast<LocksExcludedAttr>(A))
18142 Args = llvm::makeArrayRef(
LE->args_begin(),
LE->args_size());
18143 else if (
const auto *RC = dyn_cast<RequiresCapabilityAttr>(A))
18144 Args = llvm::makeArrayRef(RC->args_begin(), RC->args_size());
18145 else if (
const auto *AC = dyn_cast<AcquireCapabilityAttr>(A))
18146 Args = llvm::makeArrayRef(AC->args_begin(), AC->args_size());
18147 else if (
const auto *AC = dyn_cast<TryAcquireCapabilityAttr>(A))
18148 Args = llvm::makeArrayRef(AC->args_begin(), AC->args_size());
18149 else if (
const auto *RC = dyn_cast<ReleaseCapabilityAttr>(A))
18150 Args = llvm::makeArrayRef(RC->args_begin(), RC->args_size());
18152 if (Arg && !Finder.TraverseStmt(Arg))
18155 for (
unsigned I = 0, N = Args.size(); I != N; ++I) {
18156 if (!Finder.TraverseStmt(Args[I]))
18170 Exceptions.clear();
18173 Exceptions.reserve(DynamicExceptions.size());
18174 for (
unsigned ei = 0, ee = DynamicExceptions.size(); ei != ee; ++ei) {
18181 if (!Unexpanded.empty()) {
18192 Exceptions.push_back(ET);
18202 "Parser should have made sure that the expression is boolean");
18218 Expr *NoexceptExpr) {
18224 MethodD = FunTmpl->getTemplatedDecl();
18234 DynamicExceptionRanges, NoexceptExpr, Exceptions,
18260 Diag(DeclStart, diag::err_anonymous_property);
18285 diag::err_invalid_thread)
18293 switch (
Previous.getResultKind()) {
18300 PrevDecl =
Previous.getRepresentativeDecl();
18313 PrevDecl =
nullptr;
18317 PrevDecl =
nullptr;
18350 if (!ExplicitLists.empty()) {
18351 bool IsMemberSpecialization, IsInvalid;
18355 ExplicitLists,
false, IsMemberSpecialization, IsInvalid,
18358 if (ExplicitParams) {
18359 Info.AutoTemplateParameterDepth = ExplicitParams->
getDepth();
18360 llvm::append_range(Info.TemplateParams, *ExplicitParams);
18361 Info.NumExplicitTemplateParams = ExplicitParams->
size();
18363 Info.AutoTemplateParameterDepth = TemplateParameterDepth;
18364 Info.NumExplicitTemplateParams = 0;
18370 if (FSI.TemplateParams.size() > FSI.NumExplicitTemplateParams) {
18371 if (FSI.NumExplicitTemplateParams != 0) {